How can I find id based on its class just using javascript. I know this easily with jQuery , what is the solution .. using getElementsByTagName?
document.getElementsByClassName('myClassName')[0].id
or
document.querySelector('.myClassName').id
The first step would be to find the element with the given class name. There are currently some features supported by modern browsers, such as the getElementsByClassName and querySelector . but they are not cross browser solutions.
getElementsByClassName
querySelector
That is, getElementsByClassName not supported by IE 6-8, and querySelector not supported by IE6-7 & FF3source: http://www.quirksmode.org/dom/w3c_core.html
Therefore, if you do not support these browsers, you can use them, otherwise you will need a js shell function similar to the one mentioned in this post originally found on justswell.org .