If I click on the 1st div I want to get either 0 or 1 and if the second div 2 and so on...
None of my attempts are working:
$('div').click(function() {
//alert( $('#something').index($(this)) );
//alert( $(this).index( $('#something') ) );
console.log( $('#something').find($(this)).eq() );
});
<span id="something">
<div></div>
<div></div>
<div></div>
<div></div>
</span>
Just $(this).index()
will work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.