Wednesday, March 27, 2013

two ways of using jQuery eq() selector : note that eq selector is not there in CSS, it is a javascript extension. eq() method call is perfwise better in modern browsers



eq() selector is not a part of CSS specification
for better performance in modern browsers, use .eq() method instead.



<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
<script>
$(document).ready(function(){

  $("div:eq(1)").click(function(){alert("qqq");});
  $("div").eq(3).click(function(){alert("www");});
});
</script>
</head>
<body>
<div>aaa</div>
<div>bbb</div>
<div>ccc</div>
<div>ddd</div>
<div>eee</div>
<div>Messages will be displayed on clicking bbb,ddd, and eee above</div>
<script>
$("div").eq(4).click(function(){alert("vvv");});
</script>
</body>
</html>

No comments:

Post a Comment