this supposed to be easy task, but in fact i spent hour to solve this matter, i googled and found no solution yet, basically i would like to iterate dom element (div with IDs), here’s my code:
$j(document).ready(function(){
$j("#pinlocation").each(function(index){
alert(index+":"+$j(this).text());
});
});
on the content:
<div id="pinlocation">Test1</div>
<div id="pinlocation">Test2</div>
i replicate the error here: http://www.doxadigital.com/scrape/dummy.php
as you see, this script fails to get second “pinlocation”. Any idea what did i go wrong ?
Thanks a lot
your html is invalid because you have used the same id for more than one element. that’s why your code is not iterating for the second id.
see http://www.w3.org/TR/REC-html40/struct/global.html#h-7.5.2
Instead use class for the elements.