javascript - Finding dom index based on selection -
html markup
<div> <div class="selector"></div> </div> <div> <div class="selector"></div> </div> <div> <div class="selector1"></div> </div> <div> <div class="selector1 active"></div> </div> <div> <div class="selector2"></div> </div> <div> <div class="selector2"></div> </div>
based on user click, want find clicked bucket , based on bucket want find index.
javascript
var sectiontype = $(this).attr('class'); var sectionindex = sectiontype.find("active").index();
but not giving me selected/hover element index. can please me?
you can pass dom element index
method, returns index of element in jquery collection.
$('div[class]').click(function () { var cls = this.classname.split(' ')[0]; var index = $('div.' + cls).index(this); });
index of .active
element:
$('div[class]').click(function () { var cls = this.classname.split(' ')[0], $div = $('div.' + cls), $active = $div.filter('.active'), index = $div.index($active); console.log(cls, index); });
Comments
Post a Comment