Your bug is more than apparent. This "HTML" code is not valid HTML. The reason is: all values of all
id
attributes should be unique. If they are not unique, the page will be rendered, but the use of this attribute can give you unpredictable results.
If you support unique value of this attribute, you can get the HTML elements using it, the way you already do.
I do understand that you are trying to do some action on the whole set of elements. Of course, you can do it, and it would be a very typical use of jQuery, only you need to use some other
selectors, not
id selectors. Please see:
http://api.jquery.com/category/selectors[
^].
—SA