Manipulating DOM elements (changing content, styles, attributes)

Qus. 1 : Which of the following is used to change the content of an HTML element?

  1. element.innerHTML
  2. element.value
  3. element.content
  4. element.innerText
Qus. 2 : What is the correct way to change the background color of an element using DOM manipulation?

  1. element.background = "red";
  2. element.style.backgroundColor = "red";
  3. element.style.background = "red";
  4. element.css.backgroundColor = "red";
Qus. 3 : Which method would you use to add an event listener to an element?

  1. element.addEvent()
  2. element.addEventListener()
  3. element.attachEvent()
  4. element.onEvent()
Qus. 4 : Which method is used to replace an existing element in the DOM with a new one?

  1. replaceNode()
  2. replaceElement()
  3. replaceChild()
  4. replaceWith()
Qus. 5 : Which of the following methods can be used to remove an attribute from an HTML element?

  1. removeAttr()
  2. deleteAttribute()
  3. removeAttribute()
  4. deleteAttr()
Qus. 6 : Which of the following methods is used to insert a new element before an existing element in the DOM?

  1. insertBefore()
  2. insertPrevious()
  3. appendBefore()
  4. addBefore()
Qus. 7 : Which method is used to toggle a class on an element?

  1. classList.add()
  2. classList.remove()
  3. classList.toggle()
  4. classList.replace()
Qus. 8 : Which of the following properties is used to change the text inside an HTML element?

  1. innerHTML
  2. innerText
  3. textContent
  4. All of the above
Qus. 9 : <p>What will the following JavaScript code do?</p><pre><span style="font-size: 14px;">var element = document.getElementById("myDiv");<br></span><span style="font-size: 14px;">element.remove();</span></pre>

  1. Remove the element with the ID "myDiv" from the DOM
  2. Remove all child elements inside the element with the ID "myDiv"
  3. Hide the element with the ID "myDiv"
  4. Move the element with the ID "myDiv" to a different location
Qus. 10 : How do you insert an element before another specified element in the DOM?

  1. insertBefore()
  2. insertAfter()
  3. appendChild()
  4. prependChild()
Qus. 11 : Which of the following properties is used to check whether an element has child nodes?

  1. hasChildNodes()
  2. childNodes
  3. children
  4. hasChildren()

Programs

Latest Current Affairs 2025 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad