Get position of selected elements, not index of element in DOM

前端 未结 2 986
醉梦人生
醉梦人生 2021-01-19 15:19

Heading one

Heading two

heading caption

Heading three

相关标签:
2条回答
  • 2021-01-19 15:55

    Pass your index() a selector:

    alert($("h3").eq(2).index("h3"));
    
    0 讨论(0)
  • 2021-01-19 16:00
    <div>
       <h3>Heading one</h3>
       <h3>Heading two</h3>
       <h4>heading caption</h4>
       <h3>Heading three</h3>
    </div>
    
    <script type="text/javascript">
    $(document).ready(function(){ 
        $("div").children().each(function(){  
            $(this).click(function(){
                alert($(this).context.innerHTML);
            });  
        });
    });
    </script>`
    
    0 讨论(0)
提交回复
热议问题