Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using getElementsByName without starting at document root

Tags:

javascript

dom

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.

like image 786
14 revs, 12 users 16% Avatar asked May 10 '26 23:05

14 revs, 12 users 16%


1 Answers

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.

like image 189
Andy E Avatar answered May 12 '26 13:05

Andy E