Tuesday, October 2, 2012

Jquery: How to use index()

.index()- returns an integer indicating the position of the passed element relative to the original collection.
-1 means selector or element not found.

 Three way to use index()
1.index()

2..index( selector )
 selector A selector representing a jQuery collection in which to look for an element.
3..index( element )
element The DOM element or first element within the jQuery object to look for.

 Note : Start index is 0(Zero).

more detail- http://api.jquery.com/index

Example
<html>
<head>
  <style>div { font-weight: bold; color: #090; }</style>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
  <ul>
  <li id="foo">foo</li>
  <li id="bar">bar</li>
  <li id="baz">baz</li>
</ul>
<div></div>
 <script> 
    var listItem = $('#bar');
    $('div').html( 'Index: ' + $('li').index(listItem) );
 </script>
</body>
</html>
 
Output Demo
  • foo
  • bar
  • baz
Index: 1

Hash Table in C#

 The Hashtable is a non-generic collection and used to store the key/value pairs based on the hash code of the key. Key will be used to acce...