Java Script BASIC DOM Flashcards
What does DOM stand for?
Document Object Model
True or False: The DOM represents the structure of a web page as a tree of objects.
True
Fill in the blank: The method used to select an element by its ID in JavaScript is _____.
document.getElementById
What method would you use to select all elements with a specific class name?
document.getElementsByClassName
What is the purpose of the ‘innerHTML’ property?
To get or set the HTML content of an element.
True or False: You can modify the CSS styles of an element using the ‘style’ property.
True
What does ‘querySelector’ do?
It returns the first element that matches a specified CSS selector.
What is the function of ‘addEventListener’?
It attaches an event handler to an element.
Fill in the blank: To remove an element from the DOM, you can use the method _____.
removeChild
What method do you use to create a new HTML element in JavaScript?
document.createElement
True or False: The ‘setAttribute’ method can change the attributes of an HTML element.
True
What does ‘textContent’ do?
It gets or sets the text content of an element, excluding HTML tags.
What is the purpose of ‘appendChild’?
To add a new child node to a specified parent node.
What event is triggered when a user clicks on an element?
click
Fill in the blank: You can change the visibility of an element by setting its style.display to _____.
none
What does ‘classList’ allow you to do?
It allows manipulation of the classes of an element.
True or False: The ‘DOMContentLoaded’ event fires when the initial HTML document has been completely loaded and parsed.
True
What method would you use to stop an event from propagating?
event.stopPropagation()
What is the difference between ‘getElementById’ and ‘querySelector’?
‘getElementById’ selects an element by its ID, while ‘querySelector’ can select elements using any CSS selector.
Fill in the blank: To change the background color of an element, use element.style.backgroundColor = ‘_____’.
color
What does the ‘preventDefault’ method do?
It prevents the default action of an event from occurring.
What is a common use of ‘setTimeout’?
To execute a function after a specified delay.
True or False: You can only add one event listener per event type on an element.
False
What does ‘document.body’ refer to?
It refers to the <body> element of the document.