Created
January 24, 2012 13:30
-
-
Save elijahmanor/1670182 to your computer and use it in GitHub Desktop.
Find the jQuery Bug #2: Problem
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 id="numberList"> | |
<li data-value="1">One</li> | |
<li data-value="2">Two</li> | |
<li data-value="3">Three</li> | |
<li data-value="4">Four</li> | |
<li data-value="5">Five</li> | |
<li data-value="6">Six</li> | |
<li data-value="7">Seven</li> | |
<li data-value="8">Eight</li> | |
<li data-value="9">Nine</li> | |
<li data-value="10">Ten</li> | |
</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 { list-style-type: circle; } | |
li { margin-left: 1.5em; } |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script class="jsbin" src="http://code.jquery.com/jquery-1.7.1.min.js"></script> | |
<meta charset=utf-8 /> | |
<title>JS Bin</title> | |
<!--[if IE]> | |
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> | |
<![endif]--> | |
<style> | |
article, aside, figure, footer, header, hgroup, | |
menu, nav, section { display: block; } | |
</style> | |
</head> | |
<body> | |
<ul id="numberList"> | |
<li data-value="1">One</li> | |
<li data-value="2">Two</li> | |
<li data-value="3">Three</li> | |
<li data-value="4">Four</li> | |
<li data-value="5">Five</li> | |
<li data-value="6">Six</li> | |
<li data-value="7">Seven</li> | |
<li data-value="8">Eight</li> | |
<li data-value="9">Nine</li> | |
<li data-value="10">Ten</li> | |
</ul> | |
</body> | |
</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
function listHasNumber( $list, numberToFind ) { | |
$list.find( "li" ).each( function() { | |
if ( $( this ).data( "value" ) === numberToFind ) { | |
return true; | |
} | |
}); | |
return false; | |
} | |
var $numberList = $( "#numberList" ); | |
console.log( listHasNumber( $numberList, 0 ) ); // false | |
console.log( listHasNumber( $numberList, 1 ) ); // false | |
console.log( listHasNumber( $numberList, 5 ) ); // false | |
console.log( listHasNumber( $numberList, 10 ) ); // false | |
console.log( listHasNumber( $numberList, 15 ) ); // false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment