The basic scenario: I've got a series of elements on an HTML page, generated dynamically. (Currently, they're all divs
, but they don't need to be.)
What I want is a javascript function that will loop though all of those divs
(or whatever) looking for the presence of a specific value.
What's the best, most cross-browser way to do this? Does getElementsByName() work on divs
in all browsers? Can I give them all the same ID and get an array back out of getElementById somehow?
If I change those divs
to spans
or inputs
, does that make things easier?
Thanks!
(edit: it would be best, for this project, if there was a solution without using any external js libraries. I assume jQuery has a function that does just this in one line, but for the moment I'd like to avoid opening that can of worms with the client.)