I am developing a component which will be running on foreign sites.
How can I tell if a specific ID appears more than once on the page?
I need to know this in order to make sure that an element which is supplied to me “from the outside” is unique in that sense.
I have tried identifying this using both document.getElementById and document.querySelector, but both seem to return the first element with the non unique ID, rather than both.
jQuery and Sizzle were no help either, as they use those very same methods.
using jQuery you could use an attribute selector rather than the id selector:
which should return all elements with that Id
Working Example: http://jsfiddle.net/hunter/VvX7r/