Jquery Flashcards
Whats a DOM?
The browser’s layout engine goes through the HTML and CSS to build a “document” using the HTML Document Object Model (DOM).
How does the DOM work?
DOM has helped HTML, CSS, and JavaScript work together more effectively. It provides a standardized skeleton that all modern browsers use to make browsing the Web more effective. Many people think of the DOM as being built like a tree: it has a root and branches with nodes at the end. Alternatively, you can think of it as an x-ray for how the page is built.
Where did this whole DOM thing come from?
Web developers and designers were tired of inconsistencies across browsers and decided they needed a standard they could use to add behavior to and interact with web pages on any browser. The World Wide Web Consortium (aka W3C) worked to define the standard collaboratively with these various groups.
Whats client side scripting?
Web developers often refer to the web browser as a client because it consumes data from a (web) server. A client-side scripting language is one that can give directions to the browser behind the scenes, while a server-side language gives directions to the server.
Why create jQuery if all it does is use JavaScript? Isn’t JavaScript enough on its own?
JavaScript is great for a lot of things—especially manipulating the DOM—but it’s pretty complex stuff. DOM manipulation is by no means straightforward at the base level, and that’s where jQuery comes in. It abstracts away a lot of the complexity involved in dealing with the DOM, and makes creating effects super easy. (It was created by John Resig;
What’s this business with the dollar sign all about?
It’s just a shortcut so you don’t have to write “jQuery” over and over! But when you’re working with other client-side languages, using jQuery() helps avoid naming conflicts.
When I go to download jQuery, there’s a production version and a developer version. What’s the difference between the two?
The production version is minified, which means that a bunch of unnecessary characters and whitespace have been removed. It is optimized to run faster in a production environment, but it’s kind of harder to see what’s going on. The developer version is nicely spaced and much more readable. It’s intended for anyone who wants to dig around in the jQuery code to change or even extend it (it is open source, after all!).
(#id) ?
Selects a single element with the given id attribute. For id selectors, jQuery uses the JavaScript function document.getElementById(), which is extremely efficient.
.toggle( ) ?
Display or hide the matched elements.
.ready( ) ?
Specify a function to execute when the DOM is fully loaded. For instance: $( document ).ready(function() { console.log( “ready!” ); });
.click( ) ?
Bind an event handler to the “click” JavaScript event, or trigger that event on an element This method is a shortcut for .on( “click”, handler ) in the first two variations, and .trigger( “click” ) in the third. The click event is sent to an element when the mouse pointer is over the element, and the mouse button is pressed and released. $( “#target” ).click(function() { alert( “Handler for .click() called.” ); });
Silly mistakes to avoid?
- Misspelling selector id (“#clickME”) 2. Missing curly braces { 3. Not reading the JQuery documentation carefully
What’s happening here? $(document).ready(function( ) { $(“#clickMe”).click(function( ) { }); });
(document) - Hey, DOM… .ready - whenever you’re ready and loaded… (function( ) { - …I want you to do something for me. As soon as I possibly can, I’ll start executing code within the curly braces! $(“#clickMe”) - Here’s our ID selector for the clickMe div. .click - The dot separates the selector part from the method part. Connecting the button with an ID of clickMe to the click event, this code makes the button clickable. { }); - The code for what will happen when the button is pressed will go between these curly braces (aka the “code block”). } ) ; - The semicolon is a terminator. It ends our jQuery click statement. } ) ; - This semicolon ends our jQuery ready function.
.animate( )
Almost all css properties can be animated using jQuery .animate() method, but the property names must be CamelCased (eg: margin-top becomes marginTop), here’s syntax of jQuery animate method.
Whats happening here?
describe
.fadeOut( ) ?
Hide the matched elements by fading them to transparent.
.fadeToggle( ) ?
Display or hide the matched elements by animating their opacity
Whats happening in the following script?
** $( “button:last” ).click(function() {**
$( “p:last” ).fadeToggle( “fast”, function() {
** $( “#log” ).append( “
finished
“ );**
** });**
});
Fading in and out and appending message
After your browser receives a web page from a web server, it loads that web page into its _________.
Memory
A ____________ is used by jQuery to locate and return an element from the web page.
Selector
The JavaScript __________ translates directions you give it into different actions on the page.
Interpreter
A CSS setting that makes sure an element won’t show when the page loads, display: _____ .
none
You know you’re dealing with a ________ when you see a set of parentheses after a keyword.
method
Name of the character used to separate a jQuery selector from a jQuery method.
Dot