Tricks Flashcards
1
Q
What is the .toggleClass() method?
A
- Is a method in jQuery used to add or remove a class from a given selector.
2
Q
What is the .next() method?
A
- Is a method in jQuery used to return the next sibling from a given selector.
3
Q
What is the .attr() method?
A
- Is a method in jQuery used to return the value of an attribute or to set the value of an attribute.
4
Q
What is .each() method?
A
- Iterate over a jQuery object, executing a function for each matched element.
- Example:
$( “li” ).each(function() {
$( this ).addClass( “foo” );
});
5
Q
Why to use jQuery?
A
- Fast selection
- Cross-Browser Compatibility
- Easy DOM Manipulation
6
Q
How to run the JavaScripts correctly?
A
- A function passed into the jQuery object runs on document.ready, which occurs after the DOM has been loaded.
- External JavaScript files in the of a document are generally downloaded earlier than JavaScript files included in the . JavaScript files are also executed immediately, means they can’t access any DOM elements.
- You could include your script at the bottom of the , mean that the download could potentially start later , slowing down the initial page render.
- Correct way is to pass your function into the jQuery object, like so:
function someFunction() {
// Do interesting things
}
$(someFunction)
7
Q
What is the .css method?
A
- Get the value of a computed style property for the first element in the set of matched elements or set one or more CSS properties for every matched element.
8
Q
What is the .text method?
A
- Get the combined text contents of each element in the set of matched elements, including their descendants, or set the text contents of the matched elements.
- Is used to change the inside of tags, not to add tags.
9
Q
What is the .remove method?
A
- Remove the set of matched elements from the DOM.
- Example:
<div>
<div>Hello</div>
<div>Goodbye</div>
</div>
///Code $( ".hello" ).remove();
///Result <div class="container"> <div class="goodbye">Goodbye</div> </div>
10
Q
What are the methods .insertBefore and .insertAfter?
A
- They insert elements in the DOM that are siblings to the selected.