JQuery Flashcards
What does DOM stand for?
Document Object Model
What is the DOM?
It is the browser’s representation of the current state of the HTML content of a page
What should we not confuse the DOM with?
The html file for a page
When will the DOM look a lot like an Html file?
When the browser first loads the HTML page
When will the DOM start to look different than the original HTML file?
When the JavaScript scripts start to take over.
What is one of the things that specifically start to happen when JavaScript takes over the DOM?
Html elements can be added or removed whether or not they appeared in the HTML file
When is an example of a time where you’ve worked with a DOM?
When you view HTML in the elements panel of Chrome DevTools, you are looking at a representation of the DOM.
What is traversing?
using jQuery to find particular elements in the DOM
What is manipulation in reference to the DOM?
Updating particular elements in the DOM.
So you need to use JQuery to do DOM traversing and manipulation?
No, you can accomplish that with JavaScript on it’s own
Why is it preferred to use JQuery for DOM traversing and Manipulation if you can accomplish it with normal JavaScript?
because of cross-browser compatibility issues
How do you select elements in jquery?
$(‘___’)
In the space you add the same selectors you would in css whether it be an element or a class or an Id.
Paragraphs would be —-> $(‘p’)
Class would be ——> $(‘.className’)
Etc..
If you create a class specifically for being a target of Jquery code, what prefix should you use?
.js-
Example
p class = ‘.js-rest-of-name’
Why should we use a js prefix before our JavaScript class targets ?
Because we don’t want to use the same classes for our stying classes as the ones for our JavaScript classes - styling of a page may need to change - but your page should work even if the styling changes
Do we need to add the . On the jquery class name when applying it to the HTML elements?
No, only in JavaScript
When you have a js.file that comes after JQuery where do you put the Jquery file with the script tags?
The The js file has to come after the jquery file.
What does the jquery method .find(‘ ‘) do?
It looks and searches for all the children of an element with a particular class.
What does the .parent(‘ ‘) jquery element do?
It searches for the parent of a particular element that has a certain class
what is Event Driven DOM Manipulation?
in plain English it just means writing instructions that tell the computer to listen for when specific kinds of events happen and then do something in response.
What is a CallBack Function in Jquery?
It is a set of instructions about what to do when its particular event occurs
What are the two things you need to specify when creating an event listener?
You need to specify:
- The event, its looking for
- The call back function to happen
What type of an event occurs once a page is finished loading?
a ready event
how many times does the “ready event” happen?
once per page load
What is a ‘Ready Event Call Back Function’
is a call back function that runs when the ready event occurs
what is the syntax of the ‘Ready Event Call Back Function’?
$(CallBackFunctionName)
What is a DOM Event object?
An event object allows us to gain information about the specific event that triggered the call back function.
It can tell us everything from they type of button clicked.
The type of event
The specific element that was clicked etc
This is what an event object is
What information is available to you when it comes to DOM Event Objects?
This contains information about where you typed in the text, what keys you pressed, or which buttons were clicked. In fact, just about every piece of information you could ever want to know about how you performed an action is contained within the event object.
event.which contains what information?
contains information about which button was pressed in a mousedown event
event.key contains what information?
contains information about which key was pressed in a keydown event.
What information does event.currentTarget contain?
This contains information about which DOM element the user has interacted with.
what is event.stopPropagation( )?
Sometimes when you set a jquery selector you will chose multiple selectors, and sometimes those selectors will be children/parents of one another.. for example
$(‘div, ul, li’).click(function)
when you click on the li - you are also technically clicking on the ul and the div…. when you click on the ul
you are also clicking on the div… so your function will run for those elements also. This may not be what you want.
so you use event.stopPropagation()
when you do this we’re telling the browser to stop the event from “bubbling up” the DOM. It will run the function for the innermost clicked element and not continue up to the parent or grandparent element
what does event.preventDefault do?
it prevents the default behavior
what does the .this keyword mean in jquery?
refers to event.currentTarget. So anywhere that you have been typing out event.currentTarget, you can replace it with the this keyword
what is something you should remember about this inside of jquery?
Remember that this only refers to the element within the callback function. Outside of the callback function, it could refer to something completely different.
Will this keyword work with fat arrows the same way that it does with function keyword?
no it wont, use this with function keywords only