javascript - jQuery overall index from parent element with specific class -


how can use jquery index() method find index of parent element class related whole document click on link inside element?

the following code not work , returns -1 , know index of div element class "navi" in document...

javascript

$('.navi').on('click', 'a.link', function(event) {  var parent = $(this).closest('.navi');  var index = $(document).index(parent);  console.log(index);  return false; }); 

html

<html>  ...  <body>   ...   <div class="navi">    ...    <div class="anotherdiv">     ...     <a href="#" class="link"></a>     ...    </div>    ...   </div>   ...   <div class="navi">...</div>   ...  </body> <html/> 

try this:

$('.navi').on('click', 'a.link', function(event) {     var parent = $(this).closest('.navi');     var index = $('.navi').index(parent[0]);     console.log(index);     return false; }); 

Comments

Popular posts from this blog

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -