Answer: D) document.getElementById("paragraphID").textContent
Explanation: The "textContent" property is used to read the text content of a paragraph element in JavaScript.
Answer: C) document.getElementById("paragraphID").textContent = "new text"
Explanation: The "textContent" property is used to set the text content of a paragraph element in JavaScript.
Answer: D) innerHTML retrieves both text and HTML, while textContent retrieves only text
Explanation: "innerHTML" retrieves the HTML content (including tags), while "textContent" retrieves only the text content of the element.
Answer: D) Both B and C
Explanation: You can append text to a paragraph element using either "innerText" or "innerHTML" by using the += operator.
Answer: B) document.getElementById("paragraphID").textContent = ""
Explanation: To clear the text content of a paragraph element, you can set "textContent" to an empty string.
Answer: A) document.getElementById("paragraphID").innerHTML
Explanation: The "innerHTML" property retrieves the HTML content, including tags, of the element.
Answer: B) The paragraph will display the text "new text" without any HTML formatting
Explanation: "textContent" only retrieves and sets text, ignoring any HTML tags.
Answer: A) document.getElementById("paragraphID").innerText
Explanation: The "innerText" property can be used to read the visible text content of an element.
Answer: D) All of the above
Explanation: You can replace the text of a paragraph element using any of these properties: innerHTML, innerText, or textContent.
Answer: A) innerHTML
Explanation: The "innerHTML" property allows you to include HTML formatting when setting the text of an element.
Answer: A) document.getElementById("imageID").src = "newImage.jpg"
Explanation: The "src" property is used to change the source of an image in JavaScript.
Answer: D) Both A and B
Explanation: Both "innerText" and "textContent" can be used to change the text content of a paragraph element.
Answer: D) Both A and B
Explanation: Both backgroundImage and background properties can be used to manipulate an image in JavaScript.
Answer: D) Both B and C
Explanation: You can hide an image either by setting "style.display" to "none" or by setting "style.visibility" to "hidden".
document.getElementById("imageID").style.width = "500px";
Answer: A) It will set the width of the image to 500px.
Explanation: The code sets the width of the image element with the id "imageID" to 500px.
Answer: D) Both A and B
Explanation: You can remove an image from the page by either using the "remove()" method or by setting the "src" to an empty string.
Answer: D) Both B and C
Explanation: You can adjust the size of the image by manipulating the "style.width" or "style.height" properties.
Answer: A) document.getElementById("imageID1").src = document.getElementById("imageID2").src
Explanation: Swapping the source URLs of two images is done by setting one image's source to the other image's source.
Answer: C) Both A and B
Explanation: You can apply a class to an image by using either "className" or "classList.add".
document.getElementById("imageID").style.display = "none";
Answer: A) Hides the image from view
Explanation: This code sets the "display" style property of the image to "none", which hides the image from view.
Answer: A) document.getElementById("imageID").src = "newImage.jpg"
Explanation: You can change the source of an image by assigning a new image URL to the "src" property.
Answer: D) Both B and C
Explanation: You can either directly change the "src" or use an event listener to trigger a function that changes the image source.
document.getElementById("image1").src = document.getElementById("image2").src;
document.getElementById("image1").src = "newImage.jpg";
document.getElementById("image1").src = "image1.jpg";
document.getElementById("image1").src = "image2.jpg";
Answer: A) document.getElementById("image1").src = document.getElementById("image2").src;
Explanation: To swap images, you assign the source of one image to the other, effectively swapping their appearances.
Answer: A) Use a single function to swap image sources when an event is triggered.
Explanation: The most efficient way is to use a single function that changes the "src" of both images when an event occurs.
Answer: A) Using the "load" event listener on the image element.
Explanation: The "load" event listener can be used to detect when the image has successfully loaded after the swap.
Answer: C) Both A and B
Explanation: You can achieve this effect either with a "mouseover" event listener in JavaScript or by using the ":hover" selector in CSS.
document.getElementById("image1").src = "image2.jpg"; document.getElementById("image2").src = "image1.jpg";
document.getElementById("image1").src = "image1.jpg"; document.getElementById("image2").src = "image2.jpg";
document.getElementById("image1").src = "newImage.jpg"; document.getElementById("image2").src = "newImage2.jpg";
document.getElementById("image1").src = "newImage.jpg"; document.getElementById("image2").src = "newImage.jpg";
Answer: A) document.getElementById("image1").src = "image2.jpg"; document.getElementById("image2").src = "image1.jpg";
Explanation: This code swaps the source between two image elements with the IDs "image1" and "image2".
document.getElementById("imageID").onclick = changeImage;
document.getElementById("imageID").src = "newImage.jpg";
document.getElementById("imageID").style.visibility = "hidden";
document.getElementById("imageID").style.display = "none";
Answer: A) document.getElementById("imageID").onclick = changeImage;
Explanation: By assigning a function (like "changeImage") to the "onclick" event handler, you can easily swap images when the user clicks on the image.
Answer: D) Both A and C.
Explanation: To swap back, you either reset the "src" attributes or call the image swapping function again to revert the changes.
Answer: D) All of the above.
Explanation: If the "src" attribute contains an incorrect URL, the image will not display, and a broken image icon may appear, or a placeholder image might be shown depending on the browser settings.
document.getElementById("imageID").classList.add("newClass");
document.getElementById("imageID").classList.remove("oldClass");
document.getElementById("imageID").className = "newClass";
Answer: D) All of the above
Explanation: You can add a new class, remove an old class, or directly change the class name of an element to modify its style when swapping images.
document.getElementById("imageID").removeClass("oldClass");
document.getElementById("imageID").classList.remove("oldClass");
document.getElementById("imageID").classList.delete("oldClass");
document.getElementById("imageID").className.remove("oldClass");
Answer: B) document.getElementById("imageID").classList.remove("oldClass");
Explanation: To remove a class from an element, use the "classList.remove()" method, passing the class name you want to remove.
document.getElementById("imageID").className = "newClass newClass2";
document.getElementById("imageID").classList.add("newClass", "newClass2");
document.getElementById("imageID").classList.add("newClass newClass2");
document.getElementById("imageID").classList.replace("oldClass", "newClass newClass2");
Answer: B) document.getElementById("imageID").classList.add("newClass", "newClass2");
Explanation: You can add multiple classes using the "classList.add()" method by passing each class as a separate argument.
document.getElementById("image1").src = "image2.jpg"; document.getElementById("image1").classList.add("newClass");
document.getElementById("image2").src = "image1.jpg"; document.getElementById("image2").classList.remove("oldClass");
document.getElementById("image1").src = "newImage.jpg"; document.getElementById("image2").className = "newClass";
document.getElementById("image1").classList.add("newClass"); document.getElementById("image2").src = "image1.jpg";
Answer: A) document.getElementById("image1").src = "image2.jpg"; document.getElementById("image1").classList.add("newClass");
Explanation: You can swap images and change the class of the swapped image using both the "src" and "classList" properties.
document.getElementById("imageID").classList.toggle("class1");
document.getElementById("imageID").classList.replace("oldClass", "newClass");
document.getElementById("imageID").classList.toggle("class1", "class2");
document.getElementById("imageID").classList.add("class1"); document.getElementById("imageID").classList.remove("class2");
Answer: A) document.getElementById("imageID").classList.toggle("class1");
Explanation: The "classList.toggle()" method can be used to add the class if it is not present, or remove it if it is.
onclick = changeImageAndClass;
document.getElementById("imageID").onmouseover = changeImage;
document.getElementById("imageID").onclick = swapImageAndClass;
document.getElementById("imageID").addEventListener("click", swapImage);
Answer: C) document.getElementById("imageID").onclick = swapImageAndClass;
Explanation: The "onclick" event can be used to execute the function that swaps the image and changes the class.
document.getElementById("imageID").classList.toggle("newClass");
document.getElementById("imageID").src = "image.jpg"; document.getElementById("imageID").classList.toggle("newClass");
document.getElementById("imageID").classList.add("newClass");
document.getElementById("imageID").className = "newClass";
Answer: B) document.getElementById("imageID").src = "image.jpg"; document.getElementById("imageID").classList.toggle("newClass");
Explanation: You can swap an image by updating the "src" and toggle the class by calling "classList.toggle()" on the image element.
Answer: A) The image source will change, but the style won't be updated.
Explanation: If you don't update the class, the styling of the image will remain the same even after the source changes.
Answer: B) By changing both the "src" and "classList" properties.
Explanation: To swap both the image and its associated class, you need to update both the "src" and the "classList" properties.
Answer: A) It allows you to add, remove, or toggle classes on the image element.
Explanation: The "classList" property enables you to manipulate the classes on an element, which can be useful for styling after swapping images.
document.getElementById("elementID").style.backgroundColor = "red";
document.getElementById("elementID").setStyle("background-color: red");
document.getElementById("elementID").css("background-color", "red");
document.getElementById("elementID").setAttribute("style", "background-color: red");
Answer: A) document.getElementById("elementID").style.backgroundColor = "red";
Explanation: The correct way to set an inline style is by modifying the "style" property of the element.
document.getElementById("elementID").style = "background-color: red; color: white";
document.getElementById("elementID").style.backgroundColor = "red"; document.getElementById("elementID").style.color = "white";
document.getElementById("elementID").setAttribute("style", "background-color: red; color: white");
Answer: D) All of the above
Explanation: You can either set individual properties or directly modify the "style" attribute to apply multiple styles at once.
styleAttribute
classList
style
setAttribute("style")
Answer: C) style
Explanation: The "style" property of an element allows you to modify its CSS styles directly in JavaScript.
Answer: A) The browser will ignore the invalid property.
Explanation: If an invalid CSS property is applied, it is simply ignored, and no error occurs.
document.getElementById("elementID").style.backgroundColor = "blue";
document.getElementById("elementID").setAttribute("background-color", "blue");
document.getElementById("elementID").backgroundColor = "blue";
document.getElementById("elementID").style.background = "blue";
Answer: A) document.getElementById("elementID").style.backgroundColor = "blue";
Explanation: To set a background color via JavaScript, you use the "style.backgroundColor" property.
document.getElementById("elementID").style.visibility = "hidden";
document.getElementById("elementID").style.display = "none";
document.getElementById("elementID").visibility = "hidden";
document.getElementById("elementID").setAttribute("visibility", "hidden");
Answer: A) document.getElementById("elementID").style.visibility = "hidden";
Explanation: The "visibility" property controls whether the element is visible, and setting it to "hidden" makes the element invisible without affecting the layout.
document.getElementById("elementID").style.display = "none";
document.getElementById("elementID").style.visibility = "hidden";
document.getElementById("elementID").style.opacity = "0";
Answer: B) document.getElementById("elementID").style.visibility = "hidden";
Explanation: The "visibility" property makes the element invisible without changing its layout space, unlike "display" or "opacity".
document.getElementById("elementID").style.fontSize = "20px";
document.getElementById("elementID").fontSize = "20px";
document.getElementById("elementID").setAttribute("font-size", "20px");
document.getElementById("elementID").style.font = "20px Arial";
Answer: A) document.getElementById("elementID").style.fontSize = "20px";
Explanation: The "style.fontSize" property allows you to set the font size of an element directly.
getElementById("elementID").setAttribute("class", "newClass");
getElementById("elementID").style.className = "newClass";
getElementById("elementID").classList.add("newClass");
getElementById("elementID").style.classList = "newClass";
Answer: C) getElementById("elementID").classList.add("newClass");
Explanation: "classList.add()" allows you to add a new class to the element's class list.
document.getElementById("elementID").style = "";
document.getElementById("elementID").style.remove();
document.getElementById("elementID").removeAttribute("style");
document.getElementById("elementID").style.removeAttribute("style");
Answer: C) document.getElementById("elementID").removeAttribute("style");
Explanation: To remove the inline style, you can use the "removeAttribute()" method on the "style" attribute of the element.
<div>
elements in a document using JavaScript?document.getElementsByTagName("div");
document.querySelectorAll("div");
document.querySelector("div");
Answer: D) Both A and B
Explanation: Both getElementsByTagName()
and querySelectorAll()
can be used to target all <div>
elements. The former returns a live HTMLCollection, while the latter returns a static NodeList.
<span>
elements in a document?document.getElementsByTagName("span");
document.getElementById("span");
document.querySelector("span");
document.querySelectorAll("span");
Answer: D) document.querySelectorAll("span");
Explanation: querySelectorAll()
returns a NodeList of all matching elements, whereas getElementsByTagName()
returns an HTMLCollection.
document.getElementsByTagName("p")
method return?<p>
elements in the document.<p>
elements in the document.<p>
elements in the document.<p>
elements in the document.
Answer: B) A live HTMLCollection of all <p>
elements in the document.
Explanation: The method returns a live HTMLCollection, which means it automatically updates when elements are added or removed.
<h1>
elements in a document?document.getElementsByTagName("h1");
document.getElementById("h1");
document.querySelector("h1");
document.querySelectorAll("h1");
Answer: D) document.querySelectorAll("h1");
Explanation: querySelectorAll()
returns all matching <h1>
elements in a static NodeList, which is useful for selecting all elements of a particular tag.
getElementsByTagName()
and querySelectorAll()
?getElementsByTagName()
returns a live collection, while querySelectorAll()
returns a static NodeList.getElementsByTagName()
returns an array, while querySelectorAll()
returns a NodeList.querySelectorAll()
is more efficient than getElementsByTagName()
.
Answer: A) getElementsByTagName()
returns a live collection, while querySelectorAll()
returns a static NodeList.
Explanation: The live collection of getElementsByTagName()
automatically updates as elements are added or removed, whereas the static NodeList returned by querySelectorAll()
does not.
<div>
element in the document?document.querySelector("div");
document.getElementsByTagName("div")[0];
Answer: C) Both A and B
Explanation: Both methods will return the first <div>
element. querySelector("div")
returns the first matching element, while getElementsByTagName("div")[0]
gives the first <div>
element in the HTMLCollection.
document.querySelectorAll()
document.getElementsByTagName()
document.getElementsByClassName()
document.querySelector()
Answer: B) document.getElementsByTagName()
Explanation: getElementsByTagName()
returns a live HTMLCollection of elements, which means it updates automatically as elements are added or removed.
querySelectorAll()
over getElementsByTagName()
?querySelectorAll()
returns a static NodeList, which is easier to work with in modern web development.querySelectorAll()
allows you to use complex CSS selectors.querySelectorAll()
is faster.
Answer: B) querySelectorAll()
allows you to use complex CSS selectors.
Explanation: querySelectorAll()
allows you to use more complex selectors, like classes and IDs, whereas getElementsByTagName()
is limited to selecting elements by tag name only.
<li>
elements inside a <ul>
using CSS selectors?document.querySelector("ul li");
document.querySelectorAll("ul li");
Answer: C) Both A and B
Explanation: Both querySelector()
and querySelectorAll()
can be used to select all <li>
elements inside a <ul>
, but querySelectorAll()
returns a static NodeList, while querySelector()
returns only the first matching element.
querySelectorAll()
and getElementsByTagName()
?querySelectorAll()
returns a NodeList, while getElementsByTagName()
returns an HTMLCollection.querySelectorAll()
returns a static NodeList, while getElementsByTagName()
returns a live HTMLCollection.
Answer: C) Both A and B
Explanation: querySelectorAll()
returns a static NodeList, whereas getElementsByTagName()
returns a live HTMLCollection.
<div>
elements based on a tag name in JavaScript?document.querySelector("div");
document.getElementsByTagName("div");
document.querySelectorAll("div");
Answer: B) document.getElementsByTagName("div");
Explanation: getElementsByTagName()
targets all elements by their tag name. It returns a live HTMLCollection of all matching elements.
<span>
elements in a document?document.querySelector("span");
document.getElementsByTagName("span");
document.querySelectorAll("span");
Answer: D) All of the above
Explanation: All three methods can be used to select <span>
elements. However, querySelectorAll()
will return a static NodeList, while the others return a live HTMLCollection or just the first matching element.
querySelector()
and querySelectorAll()
?querySelector()
selects the first matching element, while querySelectorAll()
selects all matching elements.querySelector()
returns an HTMLCollection, while querySelectorAll()
returns a NodeList.querySelectorAll()
is faster than querySelector()
.
Answer: A) querySelector()
selects the first matching element, while querySelectorAll()
selects all matching elements.
Explanation: querySelector()
returns the first matching element, while querySelectorAll()
returns all matching elements as a static NodeList.
document.querySelectorAll()
document.getElementsByTagName()
document.getElementsByClassName()
document.querySelector()
Answer: B) document.getElementsByTagName()
Explanation: getElementsByTagName()
returns a live HTMLCollection, which updates automatically when elements are added or removed.
<h1>
elements in a document?document.getElementsByTagName("h1");
document.querySelector("h1");
document.querySelectorAll("h1");
Answer: D) Both A and C
Explanation: Both getElementsByTagName("h1")
and querySelectorAll("h1")
can select all <h1>
elements. However, getElementsByTagName()
returns a live HTMLCollection, while querySelectorAll()
returns a static NodeList.
querySelectorAll()
in comparison to getElementsByTagName()
?querySelectorAll()
returns a live HTMLCollection, while getElementsByTagName()
returns a static NodeList.querySelectorAll()
can select elements based on multiple selectors, while getElementsByTagName()
can only select by tag name.querySelectorAll()
is faster than getElementsByTagName()
.
Answer: B) querySelectorAll()
can select elements based on multiple selectors, while getElementsByTagName()
can only select by tag name.
Explanation: querySelectorAll()
is more flexible as it allows using multiple selectors like class names or IDs, whereas getElementsByTagName()
is limited to selecting elements based on their tag name only.
<div>
elements inside a <section>
element using JavaScript?document.getElementsByTagName("div");
document.querySelectorAll("section div");
document.querySelector("section div");
document.getElementsByTagName("section div");
Answer: B) document.querySelectorAll("section div");
Explanation: querySelectorAll("section div")
will select all <div>
elements inside a <section>
element.
document.getElementsByTagName("div")[0]
return?<div>
element in the document.<div>
elements.<div>
elements.<div>
element in the document.
Answer: A) The first <div>
element in the document.
Explanation: The method getElementsByTagName("div")[0]
returns the first <div>
element in the HTMLCollection.
<img>
elements in the document?document.querySelectorAll("img");
document.getElementsByTagName("img");
Answer: C) Both A and B
Explanation: Both querySelectorAll()
and getElementsByTagName()
can be used to select all <img>
elements in the document.
getElementsByTagName()
return?
Answer: C) A live HTMLCollection.
Explanation: getElementsByTagName()
returns a live HTMLCollection, meaning the collection automatically updates as elements are added or removed from the DOM.
Answer: B) A set of HTML elements that can be manipulated
Explanation: The DOM represents the structure of an HTML document as a tree of objects, each representing a part of the page, such as elements, attributes, and text. It allows JavaScript to manipulate the page dynamically.
getElementById()
getElementByName()
getElementsByTagName()
querySelector()
Answer: A) getElementById()
Explanation: getElementById()
is a DOM method that allows you to select an element by its unique ID. It returns the first element with the matching ID or null
if no such element is found.
getElementById()
getElementsByClassName()
getElementsByTagName()
querySelector()
Answer: B) getElementsByClassName()
Explanation: getElementsByClassName()
returns a live HTMLCollection of all elements in the document with the specified class name.
appendChild()
insertBefore()
removeChild()
replaceChild()
Answer: A) appendChild()
Explanation: appendChild()
adds a new child node to the end of the list of children of a specified parent node.
element.innerHTML = "new text";
element.textContent = "new text";
element.setAttribute("text", "new text");
Answer: D) A and B
Explanation: Both innerHTML
and textContent
can be used to change the text content of an element. innerHTML
also includes HTML tags, while textContent
changes only the text.
Answer: B) It allows JavaScript to interact with HTML and CSS.
Explanation: The DOM allows JavaScript to manipulate the structure, style, and content of a document dynamically, enabling interactive web pages.
parentNode.removeChild(childNode);
parentNode.deleteChild(childNode);
parentNode.detachChild(childNode);
parentNode.deleteNode(childNode);
Answer: A) parentNode.removeChild(childNode);
Explanation: The removeChild()
method removes a specified child node from its parent node.
getElementsByTagName()
?
Answer: B) A live HTMLCollection
Explanation: getElementsByTagName()
returns a live HTMLCollection, which automatically updates when elements are added or removed from the DOM.
element.getAttribute("attributeName");
element.attributeName;
element.get("attributeName");
element.getValue("attributeName");
Answer: A) element.getAttribute("attributeName");
Explanation: getAttribute()
retrieves the value of the specified attribute from an element.
<div>
elements that are children of a <section>
element?document.querySelector("section div");
document.getElementsByTagName("div");
document.querySelectorAll("section div");
Answer: D) Both A and C
Explanation: Both querySelector("section div")
and querySelectorAll("section div")
can be used to select all <div>
elements that are children of a <section>
element.
node.getParent()
node.parentElement
node.parentNode()
node.getParentElement()
Answer: B) node.parentElement
Explanation: The parentElement
property is used to access the parent element of a node in the DOM.
element.getChildNodes()
element.children()
element.childNodes
element.getChild()
Answer: C) element.childNodes
Explanation: The childNodes
property returns a NodeList of all child nodes of a given element, including text nodes and comment nodes.
parent.appendChild(newElement)
parent.insertChild(newElement)
parent.addChild(newElement)
parent.appendChild(newElement, true)
Answer: A) parent.appendChild(newElement)
Explanation: The appendChild()
method adds a new child node to the end of the list of children of a specified parent node.
parent.removeChild(child)
parent.deleteChild(child)
parent.detachChild(child)
parent.removeNode(child)
Answer: A) parent.removeChild(child)
Explanation: The removeChild()
method is used to remove a specified child node from its parent node.
parentNode
property do in the DOM?
Answer: C) It gets the parent node of an element.
Explanation: The parentNode
property returns the parent node of the specified element, or null
if the element has no parent.
parentElement
for a root element that has no parent?null
Answer: A) It returns null
Explanation: If the element is a root element (such as <html>
), the parentElement
will return null
since it has no parent element.
childNodes
and children
in the DOM?childNodes
returns a live list, and children
returns a static list.childNodes
includes all types of nodes (like text nodes), while children
only includes element nodes.childNodes
is faster than children
.childNodes
and children
.
Answer: B) childNodes
includes all types of nodes (like text nodes), while children
only includes element nodes.
Explanation: childNodes
returns all types of child nodes (including text and comment nodes), while children
only returns element nodes.
insertBefore()
insertAfter()
appendChild()
addChild()
Answer: A) insertBefore()
Explanation: The insertBefore()
method inserts a new node before a specified existing child node of the parent element.
parentNode
and parentElement
properties?parentNode
returns a node, and parentElement
returns an element.parentNode
only works with element nodes, and parentElement
works with all nodes.parentElement
is not supported by modern browsers.
Answer: A) parentNode
returns a node, and parentElement
returns an element.
Explanation: parentNode
can return a node, such as a text or comment node, whereas parentElement
always returns an element node.
node.hasParent()
node.hasParentElement()
node.parentNode !== null
node.parentElement !== null
Answer: C) node.parentNode !== null
Explanation: To check if a node has a parent, you can verify if its parentNode
is not null
.
parent.getElementsByTagName()
parent.querySelectorAll()
parent.children()
parent.getChildrenByTagName()
Answer: A) parent.getElementsByTagName()
Explanation: The getElementsByTagName()
method retrieves all child elements of a parent element that match the specified tag name.
parent.children
return?
Answer: D) A live HTMLCollection of child element nodes.
Explanation: The children
property returns a live HTMLCollection of child elements of the specified element, excluding text and comment nodes.
parent.firstChildElement
parent.firstElementChild
parent.firstChild()
parent.getFirstChild()
Answer: B) parent.firstElementChild
Explanation: The firstElementChild
property returns the first child element of the parent element (ignoring text and comment nodes).
parent.querySelectorAll('.className')
parent.getElementsByClassName('.className')
parent.querySelectorAll('.className').children
parent.getElementsByClassName('.className').childNodes
Answer: A) parent.querySelectorAll('.className')
Explanation: The querySelectorAll()
method allows you to select all children elements that match a specific class name.
parent.lastChildElement
parent.lastElementChild
parent.lastChild()
parent.getLastChild()
Answer: B) parent.lastElementChild
Explanation: The lastElementChild
property returns the last child element of the parent element, excluding text and comment nodes.
parent.firstChild()
parent.firstElementChild
parent.getFirstChild()
parent.firstChildNode()
Answer: A) parent.firstChild()
Explanation: The firstChild
property retrieves the first child node of a parent element, including text and comment nodes.
childNodes
and children
in DOM traversal?childNodes
returns only element nodes, while children
returns all types of nodes.childNodes
returns all types of nodes, including text and comment nodes, while children
only returns element nodes.childNodes
returns a static list, while children
returns a live list.childNodes
and children
.
Answer: B) childNodes
returns all types of nodes, including text and comment nodes, while children
only returns element nodes.
Explanation: The childNodes
property returns all child nodes, including text and comment nodes, while children
only returns child element nodes.
parent.getChildAt(index)
parent.children[index]
parent.getChild(index)
parent.childNodes(index)
Answer: B) parent.children[index]
Explanation: The children
property returns an HTMLCollection, which allows direct access to child elements by their index using array-like notation.
parent.hasChildren()
parent.hasChildNodes()
parent.children.length > 0
parent.getChildElements().length > 0
Answer: B) parent.hasChildNodes()
Explanation: The hasChildNodes()
method checks if the specified parent element has any child nodes.
parent.lastChildElement
parent.lastElementChild
parent.lastChild
parent.lastNodeChild
Answer: C) parent.lastChild
Explanation: The lastChild
property returns the last child node of the specified element, including text and comment nodes.