w6d2-d5 - javascript/jquery/dom Flashcards
How does document.createElement add an object into the page?
It doesn’t.
to append to the page, use [some HTMLElement].appendChild(obj)
How do we listen for changes on something in the page?
EventTarget#addEventListener
Pass in a callback.
What are the 3 ways to call $ or jQuery
- select elements using CSS selectors
- pass it HTML code
- pass it an HTMLElement: it will create a jQuery object wrapping that one element.
What are the primary functions of jQuery
selection
traversal
inserting and removing elements
What’s the jQuery syntax for an eventListener?
jQuery#on(eventName, callback)
What’s the jQuery syntax to stop listening to an event?
jQuery#off(eventName, callback)
What property of the Event object tells us what it is currently focused on?
currentTarget
Does jQuery wait until the page loads before it runs?
No. It executes just like regular JS.
How do you ensure that the page is loaded before running jQuery code? (3 ways(
- Put the script tags at the very bottom of the body.
- set a window.onload callback.
- use ready-style:
$(someFunction)
This will take a function to run and call that function when the DOM is fully loaded
What’s the value of event delegation?
Rather than install many identical event handlers on many identical elements, we install one handler for a group of elements (the root element) and call the appropriate element when we hear about an event.
How do you set up event delegation in jQuery?
on.(event, css_selector, callback)
What are the properties of the object passed in to $.ajax and what does each do?
method: [‘POST’ , ‘GET’ , …]
url: ‘/someUrl’
dataType: ‘json’
data: body of our request (object or string)
success: callback
How do you locate an element inside of another element?
$el.find(“div”)
What does this do:
$el.find(“div”)
?
Finds a div inside of a jQuery element $el
The error “something is not a constructor” is indicative of what?
module.exports was not set within the class definition .js file.