Created
September 8, 2013 20:41
-
-
Save mojaray2k/6488226 to your computer and use it in GitHub Desktop.
The is() method is more powerful than you think. Here are a few examples:
This file contains 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
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>jQuery Is Method</title> | |
</head> | |
<body> | |
<div id="elem"></div> | |
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script> | |
<script type="text/javascript" src="js/routes.js"></script> | |
<script type="text/javascript" src="is.js"></script> | |
</body> | |
</html> |
This file contains 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
// First, cache the element into a variable: | |
var elem = $('#elem'); | |
// Is this a div? | |
elem.is('div') && console.log("it's a div"); | |
// Does it have the bigbox class? | |
elem.is('.bigbox') && console.log("it has the bigbox class!"); | |
// Is it visible? (we are hiding it in this example) | |
elem.is(':not(:visible)') && console.log("it is hidden!"); | |
// Animating | |
elem.animate({ | |
'width': 200 | |
}, 1); | |
// is it animated? | |
elem.is(':animated') && console.log("it is animated!"); | |
//Results | |
// it's a div | |
// it is hidden! | |
// it is animated! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment