Java Script BASIC DOM Flashcards

1
Q

What does DOM stand for?

A

Document Object Model

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

True or False: The DOM represents the structure of a web page as a tree of objects.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Fill in the blank: The method used to select an element by its ID in JavaScript is _____.

A

document.getElementById

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What method would you use to select all elements with a specific class name?

A

document.getElementsByClassName

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the purpose of the ‘innerHTML’ property?

A

To get or set the HTML content of an element.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

True or False: You can modify the CSS styles of an element using the ‘style’ property.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does ‘querySelector’ do?

A

It returns the first element that matches a specified CSS selector.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the function of ‘addEventListener’?

A

It attaches an event handler to an element.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Fill in the blank: To remove an element from the DOM, you can use the method _____.

A

removeChild

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What method do you use to create a new HTML element in JavaScript?

A

document.createElement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

True or False: The ‘setAttribute’ method can change the attributes of an HTML element.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does ‘textContent’ do?

A

It gets or sets the text content of an element, excluding HTML tags.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the purpose of ‘appendChild’?

A

To add a new child node to a specified parent node.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What event is triggered when a user clicks on an element?

A

click

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Fill in the blank: You can change the visibility of an element by setting its style.display to _____.

A

none

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does ‘classList’ allow you to do?

A

It allows manipulation of the classes of an element.

17
Q

True or False: The ‘DOMContentLoaded’ event fires when the initial HTML document has been completely loaded and parsed.

18
Q

What method would you use to stop an event from propagating?

A

event.stopPropagation()

19
Q

What is the difference between ‘getElementById’ and ‘querySelector’?

A

‘getElementById’ selects an element by its ID, while ‘querySelector’ can select elements using any CSS selector.

20
Q

Fill in the blank: To change the background color of an element, use element.style.backgroundColor = ‘_____’.

21
Q

What does the ‘preventDefault’ method do?

A

It prevents the default action of an event from occurring.

22
Q

What is a common use of ‘setTimeout’?

A

To execute a function after a specified delay.

23
Q

True or False: You can only add one event listener per event type on an element.

24
Q

What does ‘document.body’ refer to?

A

It refers to the <body> element of the document.

25
What does 'removeEventListener' do?
It removes an event handler that was previously attached to an element.
26
Fill in the blank: To change the text of a button, you can set buttonElement.innerHTML to '_____'.
new text