Are you ready?
1 questions to solve.
- This quiz goes to full-screen once you press the Start button, or any Next button after exiting the quiz window.
- At the end of the quiz, you are able to review all the questions that you answered wrong and see their explanations.
eleusing one of the following choices.
parentNodepoints to the parent node of a given element. All other choices shown here are invalid properties. Hence, the choice (C).
.main .title .t1.
querySelector()selects the first element that matches a given selector string. Hence, the choice (A).
Consider the code below.
<div id="t1"> <p>A paragraph</p> </div>
getElementsByTagName()both return a list of the matched elements, even if the match is for a single element.
True or false?
div.className += " intro"do to the
<div>element shown below, assuming it has been selected in the variable
<div class="a1">A div</div>
div.className += " intro"will set
"a1 intro". That is,
divnow has a new class
elein the position show below. You shall assume that
#div1is saved in the variable
<div id="div1">I am Div1</div> <!--Add ele here--> <div id="div2">I am Div2</div>
appendChild()is useless here since it can add a node only at the end of an element.
insertBefore()is the solution here.
The first argument of
insertBefore()is the node to be added, whereas the second argument is the child before which to add. This goes with choice (D).
idattribute of an element
elebe retrieved? You may assume that
elehas only one attribute on it and that is
idpoints to its
attributespoints to the list of all its attributes where a given attribute can be accessed via its name and its position in the element's markup.
This means that for
idattribute can be accessed in all the first three ways described which goes with choice (D).
navfrom the following element? Choose all the possible choices in relation to this example.
<p class="nav">I am Div1</p>
var p = document.getElementsByClassName("nav");
footo the text
innerTextproperties can be used to change the content of an element. The main difference is that
innerHTMLsupports HTML tags in the assignment string, whereas
You may assume it has already been fetched in the variable
<p>The first paragraph</p> <!-- Remove the following paragraph --> <p>Another paragraph</p>
eleis to go to its parent element using its
parentNodeproperty, and then call the
removeChild()method on it. This goes with choice (A).
data-attributes of an element?
"Hello"to an empty element node
eleis empty i.e has no content in it, we can use any of three statements shown below to add
"Hello"to it. Hence, the choice (D).
var a = document.getElementById("article"); a.appendChild("<p>A paragraph</p>");
Nodeobjects. For more info, refer to HTML DOM Elements.