Is there a way to use getElementsByName without starting from the DOM root.
For example I have a div element, and want to start searching from that element.
If not, then do I have to write my own function that recursively iterates through the child nodes, or is there a different way to do it.
getElementsByName and getElementById are both members of the document object, and aren't part of the HTMLElement prototype. In modern browsers (IE8, Firefox, Chrome, Opera), you can use element.querySelectorAll("*[name='myName']").
Other than that your alternative is to use a library like Sizzle or a framework such as jQuery (which uses Sizzle) to handle selectors.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With