I'm having trouble understanding jqueries.each. I have the following code:
$('#testDiv').each(function(index, domEle){ $(this).text(index); });
and the following HTML
<div id="p18"> <div class="inner"> <span>...</span> <p class="right">...</p> <div id="testDiv"></div> </div> </div> <div id="p19"> <div class="inner"> <span>...</span> <p class="right">...</p> <div id="testDiv"></div> </div> </div> <div id="p20"> <div class="inner"> <span>...</span> <p class="right">...</p> <div id="testDiv"></div> </div> </div>
When the script runs, it only works for the first testDiv, since it sets the text correctly to 0, but the other testDivs.
My common goal is to write a script that sets the div height based on a different div height. The height is different, so I think the loop structure is the way to go (if I'm not mistaken?)
What am I doing wrong with jq code?
source share