This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$( "a" ).attr( "href" ); // Returns the href for the first a element in the document |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$( "#myId" ); // Note IDs must be unique per page. | |
$( ".myClass" ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The .html() method used as a setter: | |
$( "h1" ).html( "hello world" ); | |
// The .html() method used as a getter: | |
$( "h1" ).html(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Viewing the number of <h1> tags on the page. | |
var allHeadings = $( "h1" ); | |
alert( allHeadings.length ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Setting CSS properties. | |
$( "h1" ).css( "fontSize", "100px" ); // Setting an individual property. | |
// Setting multiple properties. | |
$( "h1" ).css({ | |
fontSize: "100px", | |
color: "red" | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Returns "lots of extra whitespace" | |
$.trim( " lots of extra whitespace " ); | |
var myArray = [ 1, 2, 3, 5 ]; | |
if ( $.inArray( 4, myArray ) !== -1 ) { | |
console.log( "found it!" ); | |
} | |
<ul> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul> | |
<div class="test"></div> | |
<li id="foo1">foo</li> | |
<li id="bar1" class="test">bar</li> | |
<li id="baz1">baz</li> | |
<div class="test"></div> | |
</ul> | |
<div id="last"></div> | |
var foo = $( "li" ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Disable #x | |
$( "#x" ).prop( "disabled", true ); | |
// Enable #x | |
$( "#x" ).prop( "disabled", false ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Event setup using a convenience method | |
$( "p" ).click(function() { | |
console.log( "You clicked a paragraph!" ); | |
}); | |
// Equivalent event setup using the `.on()` method | |
$( "p" ).on( "click", function() { | |
console.log( "click" ); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The hover helper function | |
$( "#menu li" ).hover(function() { | |
$( this ).toggleClass( "hover" ); | |
}); | |
// The toggle helper function | |
$( "p.expander" ).toggle( function() { | |
$( this ).prev().addClass( "open" ); | |
}, function() { | |
$( this ).prev().removeClass( "open" ); |