Can you please tell me if there is any DOM API which search for an element with given attribute name and attribute value:
Update: In the past few years the landscape has changed drastically. You can now reliably use
querySelectorAll, see Wojtek's answer for how to do this.
There's no need for a jQuery dependency now. If you're using jQuery, great...if you're not, you need not rely it on just for selecting elements by attributes anymore.
If a library like jQuery is an option, you can do it a bit easier, like this:
If the value isn't a valid CSS identifier (it has spaces or punctuation in it, etc.), you need quotes around the value (they can be single or double):
You can also do
contains, etc...there are several options for the attribute selector.