More In Detail DOM Flashcards
1
Q
Answer the following three questions:
- What are the outermost elements called?
- What are the elements directly inside of it called?
- What are the elements called with the same parent, on the same level?
A
- Parent
- Children
- Siblings
2
Q
What is the difference between the closest and next methods.
A
The closest method finds the closest acestor of the selected element. So parent, grandparents etc.
The next method finds the next sibling of the selected element.
3
Q
Based on the code below, using a certain method, how could you select the heading one element?
<div class="container"> <h1> Welcome Home </h1> <p> You can rest easy</p> <p> Relax</p> </div>
A
$(‘.container’).find(‘h1’);
4
Q
Based on the code below, if you wanted to toggle the class ‘highlight’ for the div ‘info’ but not the div ‘container when you clicked on the element with the id ‘go’, which answer would accomplish that?
<div class="container"> <p> we all go home at some point</p> <div class="info"> <h1> Welcome Home </h1> <p> You can rest easy</p> <p> Relax</p> <p> You belong here</p> </div></div>
A
$(‘#go’).on(‘click’, function() {
$(‘#rest’).closest(‘div’).toggleClass(‘highlight’);
})