I can say what I can see from your code. The problem is not the method
.each
which of course should traverse the full set of elements, but the set of element itself, more exactly, the selector you use.
Your selector is the "id selector", based on the attribute
id
. The purpose of this attribute is the
unique identification of some element. So, the selector should not make a set of more then one element, by definition. Now, your HTML actually contains more then one case of
id="pcnt"
. In other words,
this is not a valid HTML. I don't know how JavaScript is supposed to act on invalid HTML and I don't know if it is ever prescribed by the ECMAScript standard. You should rather be on the
safe side and
assume that JavaScript can give you unpredictable results. In other way, you should
always provide valid HTML.
I hope you got the point. Now, what to do in your case? How to traverse all the
div
elements you want? It's really up to you, but you certainly need to use some other selector. For example, they can have some common CSS class applied only to these DIVs; or you can have only these DIVs on the whole page. Look at the available selectors to see the possibilities you can use:
http://api.jquery.com/category/selectors/[
^].
See also:
http://api.jquery.com/jQuery.each/[
^],
http://api.jquery.com/id-selector/[
^],
http://en.wikipedia.org/wiki/ECMAScript[
^].
—SA