What JavaScript function retrieves all elements with a specified tag name?
document.getElementsByTagName()
What does document.getElementsByTagName() return?
A live HTMLCollection of all elements matching the tag name.
What does document.getElementById() return?
A single element matching the specified ID.
Example of using getElementsByTagName to count paragraphs
const paragraphs = document.getElementsByTagName("p"); console.log(paragraphs.length);
What is the purpose of the <noscript> tag?</noscript>
To display alternative content if JavaScript is disabled or unsupported.
Where should <noscript> be placed?</noscript>
Inside the <body> element to provide fallback content.
Example of a <noscript> tag</noscript>
<noscript>JavaScript is disabled — please enable it for full functionality.</noscript>
Why should scripts be placed at the bottom of an HTML page?
To allow HTML to load before scripts execute, improving load time.
Alternative to placing scripts at bottom of HTML
Use the defer attribute in the
tag.
Example of using defer in script tag
<script src="app.js" defer></script>
What is the proper way to access a form field named field1 inside a form named form1?
document.forms[“form1”].elements[“field1”]
Why is document.field1 invalid?
It doesn’t specify the form hierarchy and will not find nested fields.
Example of accessing a form field value
let value = document.forms["form1"].elements["field1"].value;
What is the integer value for TEXT_NODE in the DOM?
3
Which DOM node type has value 1?
ELEMENT_NODE
Which DOM node type has value 2?
ATTRIBUTE_NODE
Which DOM node type has value 3?
TEXT_NODE
Which DOM node type has value 8?
COMMENT_NODE
Example of checking for TEXT_NODE in code
if (node.nodeType === 3) { console.log("This is a text node"); }
Why is document.getElementsByTagName() preferred over getElementById() for tag-based selection?
Because it retrieves multiple elements rather than just one.
What kind of collection does getElementsByTagName() return?
A live HTMLCollection that updates if the DOM changes.
What does the <noscript> tag improve?</noscript>
Accessibility and user experience for browsers without JavaScript.
How can script placement affect performance?
Scripts at the top block rendering; placing them later improves perceived load speed.
How can you access a specific form in the DOM?
Use document.forms[index] or document.forms["formName"]
Hello World!
and appends it: var newPara=document.createElement('p'); var newText=document.createTextNode('Hello World!'); newPara.appendChild(newText); document.body.appendChild(newPara);"