I am trying to traverse html using jQuery .
You can see the html code in the image. when I hover the mouse over a star the code is triggered
the code finds the span two levels up using parent().parent(). and then gets all the fa-star elements using jquery "find" method. when I loop the code I expect the loop to print 5 items. but it prints about 24 of them.
what can be the cause of this behaviour?
This is the javascript code I use,
$(".fa-star").bind("mouseover", function(e){
var star_elements = $(this).parent().parent()
star_elements.find(".fa-star").each(function(i,elem) {
console.log(i + $(elem).attr("class"));
})
})
<span id="view:_id1:_id338:_id343:repeat2:0:stars">
<span id="view:_id1:_id338:_id343:repeat2:0:_id442:inlineaction" class="kompetensdlg" style="background-color: red;">
<a id="view:_id1:_id338:_id343:repeat2:0:_id442:link5" href="#" title="Grund"><i id="view:_id1:_id338:_id343:repeat2:0:_id442:computedField1" class="fa fa-star yellowstar"></i></a><a id="view:_id1:_id338:_id343:repeat2:0:_id442:link10" href="#" title="God"><i id="view:_id1:_id338:_id343:repeat2:0:_id442:computedField2" class="fa fa-star yellowstar"></i></a><a id="view:_id1:_id338:_id343:repeat2:0:_id442:link4" href="#" title="Utmärkt"><i id="view:_id1:_id338:_id343:repeat2:0:_id442:computedField3" class="fa fa-star yellowstar"></i></a><a id="view:_id1:_id338:_id343:repeat2:0:_id442:link6" href="#" title="Avancerad"><i id="view:_id1:_id338:_id343:repeat2:0:_id442:computedField4" class="fa fa-star yellowstar"></i></a><a id="view:_id1:_id338:_id343:repeat2:0:_id442:link7" href="#" title="Expert"><i id="view:_id1:_id338:_id343:repeat2:0:_id442:computedField5" class="fa fa-star yellowstar"></i></a><span id="view:_id1:_id338:_id343:repeat2:0:_id442:computedField6" class="kmsg"></span></span>
</span>