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
// Instantaneously toggle the display of all paragraphs | |
$( "p" ).toggle(); | |
// Slowly toggle the display of all images | |
$( "img" ).toggle( "slow" ); | |
// Toggle the display of all divs over 1.8 seconds | |
$( "div" ).toggle( 1800 ); | |
// Toggle the display of all ordered lists over 1 second using slide up/down animations |
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
// Hide all paragraphs using a slide up animation over 0.8 seconds | |
$( "p" ).slideUp( 800 ); | |
// Show all hidden divs using a slide down animation over 0.6 seconds | |
$( "div.hidden" ).slideDown( 600 ); | |
// Hide all paragraphs using a fade out animation over 1.5 seconds | |
$( "p" ).fadeOut( 1500 ); | |
// Show all hidden divs using a fade in animation over 0.75 seconds |
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
// Instantaneously hide all paragraphs | |
$( "p" ).hide(); | |
// Instantaneously show all divs that have the hidden style class | |
$( "div.hidden" ).show(); | |
// Slowly hide all paragraphs | |
$( "p" ).hide( "slow" ); | |
// Quickly show all divs that have the hidden style class |
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
// When a user focuses on or changes any input element, we expect a console message | |
// bind to multiple events | |
$( "div" ).on( "mouseenter mouseleave", function() { | |
console.log( "mouse hovered over or left a div" ); | |
}); |
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 many ways to bind events with jQuery | |
// Attach an event handler directly to the button using jQuery's | |
// shorthand `click` method. | |
$( "#helloBtn" ).click(function( event ) { | |
alert( "Hello." ); | |
}); | |
// Attach an event handler directly to the button using jQuery's | |
// `bind` method, passing it an event string of `click` | |
$( "#helloBtn" ).bind( "click", function( event ) { |
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" ); |
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
// 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
<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
// 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> |