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
// 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
// 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
// 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 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
// Create a button to stop all animations on the page: | |
$( "<button type='button'></button>" ) | |
.text( "Stop All Animations" ) | |
.on( "click", function() { | |
$( "body *" ).filter( ":animated" ).stop(); | |
}) | |
.appendTo( document.body ); |
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 level 1 headings over half a second; then wait for 1.5 seconds | |
// and reveal all level 1 headings over 0.3 seconds | |
$( "h1" ).hide( 500 ).delay( 1500 ).show( 300 ); |
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
// Custom effects with .animate() | |
$( "div.funtimes" ).animate({ | |
left: "+=50", | |
opacity: 0.25 | |
}, | |
300, // Duration | |
function() { // Callback when the animation is finished | |
console.log( "done!" ); | |
} | |
); |
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
$(function() { | |
// Let's do something with Google Maps: | |
var canvas = $( "#map_canvas" ); | |
var myLatlng = new google.maps.LatLng( -34.397, 150.644 ); | |
var myOptions = { | |
zoom: 8, | |
center: myLatlng, | |
mapTypeId: google.maps.MapTypeId.ROADMAP |
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
function toast(message) { | |
var $toast = $('<div class="ui-loader ui-overlay-shadow ui-body-e ui-corner-all"><h3>' + message + '</h3></div>'); | |
$toast.css({ | |
display: 'block', | |
background: '#fff', | |
opacity: 0.90, | |
position: 'fixed', | |
padding: '7px', | |
'text-align': 'center', |