JS In the Browser Flashcards

1
Q

binding to key browser load lifecycle events

A

RESEARCH

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

creating DOM nodes and injecting them into the DOM

A

RESEARCH

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

useing data- attributes

A

RESEARCH

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

What are browser tools you can use to debug?

A
  • Inspector in your browser’s dev tools
  • Sources Tab - Step through the code using breakpoints
  • Network tab - requests
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

optimizing performance of DOM reads & writes

A

RESEARCH

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

using localStorage and sessionStorage

A

RESEARCH

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

Describe jQuery’s.ready feature

A

DOM.Ready has 3 states:
Loading - still loading
Interactive - loaded and parsed
Complete - all sub resources including images and stylesheets have been loaded

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

Event Bubbling

A

Event handlers ‘bubble’ up from the child to its ancestor element.

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

What is the DOM?

A

Document Object Model

  • treats HTML, XML, XHTML as a tree structure, each node represents a DOM object with the Document as the root
  • ‘map’ of a webpage
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a Global Variable?

A

Part of a single global object - in the browser it is the Window object

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

How does JS interact with the DOM?

A

You can select elements and manipulate them through JS.

You can listen for events / user interactions and run a function based on them.

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

What is the difference between document.getElementById and document.getElementsByTagName?

A

document. getElementById requires an id as an argument and returns a single element.
document. getElementsByTagName requires an HTML tag and returns an array.

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

What are the 2 most flexible selectors to grab html elements from the DOM?

A

document.querySelector and document.querySelectorAll

document. querySelector grabs the first element it finds
document. querySelector grabs all the elements in the collection

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

What is the difference between innerHTML and textContent?

A

textContent returns the value inside an HTML tag

innerHTML returns the html element and its value inside of a string

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

How can you change an attribute inside of an element?

A

You can use dot notation to access that property and reassign its value.

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

How do you get and set an element’s class?

A

You can do that by accessing its className property.

17
Q

What is the difference between a node and an element in the DOM?

A

A node belongs to the tree data structure in the DOM and an element is plain HTML.

18
Q

Explain how I would add a node to the DOM

A

I would create an element and then use appendChild, pass an element into that in order to add this node to the DOM.

19
Q

What are 3 steps to make your site interactive?

A
  1. Select elements in the DOM.
  2. Manipulate elements
  3. Listen for user actions
20
Q

What is EventTarget?

A

EventTarget object can be the element, or the window object.

21
Q

How does addEventListener work?

A

addEventListener takes a DOM event type, and a callback function, called an eventHandler

22
Q

What is the event object?

A

It contains methods that can be applied as event handlers to an event listener.

23
Q

How do you make sure the target method on the event object triggers for a specific element?

A

Write a condition in your addEventListener function and add the tagName method to the event.target and assign it the html element type.

if (event.target.tagName == ‘LI’)

24
Q

How would you insert a node before the reference node as a child of the current node?

A

Use insertBefore