HTML/Javascript questions: A. What property references the parent of a node? B.
ID: 3736731 • Letter: H
Question
HTML/Javascript questions:
A. What property references the parent of a node?
B. What object references the third child node of an object?
C. For an element node representing a blockquote element, what values returned by the nodeType, nodeName, and nodeValue properties?
D. Provide a command to create a node containing the text string “U.S. Constitution”. Store the node in the docText variable. Provide another command to create an h2 element node, storing the node in the mainTitle variable. Provide a command to append the docText variable to the mainTitle variable.
Explanation / Answer
Question A
What property references the parent of a node?
Answer
For this let us assume a element inside the html body, here i use UL element
Example
<html>
<body>
<ul>
<li id="list1">1</li>
<li id="list2">2</li>
<li id="list3">3</li>
</ul>
</body>
</html>
In the above example code, if we consider the li element the parent will be ul, and if you go for ul the parent will be body. And there is no parent element for body as it is the top most element in html
And the property refers the parent node in javascript is
The above code written by considering the example given above, and the return result of above code is element <ul>
Question B
What object references the third child node of an object?
Answer
In this we will consider the below html code
Example
<html>
<body>
<div id="parentDiv">
<div>1<div>
<div>2<div>
<div>3<div>
</div>
</body>
</html>
In the above code let us assume the div with id parentDiv, if we take this the childs are div with values 1, 2 and 3 so the third childNode for the parentDiv is div with value 3 (highlighted in above example)
The property object refers the third childnode is
Question C
For an element node representing a blockquote element, what values returned by the nodeType,nodeName, and nodeValue properties?
Answer
Below is the example for blockquote in html
Example
<html>
<body>
<blockquote id="blockQuote" cite="xxx.html">
<p>Test Paragraph</p>
</blockquote>
</body>
</html>
The above code is just for your idea of how the blockquote used in html.
Here the blockquote serves as element to html so the node property values are given below
Question D
Provide a command to create a node containing the text string “U.S. Constitution”. Store the node in the docText variable. Provide another command to create an h2 element node, storing the node in the mainTitle variable. Provide a command to append the docText variable to the mainTitle variable.
Answer
Below is the code which creates node for string and then creates node for h1 element and then appends the string node to element node h1
var docText = document.createTextNode("U.S. Constitution");
var mainTitle = document.createElement("H1");
mainTitle.appendChild(docText);
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.