Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  10] [ 5]  / answers: 1 / hits: 29434  / 15 Years ago, wed, may 27, 2009, 12:00:00

is there a way to join 2 NodeLists returned by 2 calls of document.getElementsByTagName?



Say, I have the following code



var inputs = documentElement.getElementsByTagName('input');
var selects = document.getElementsByTagName('select');


I want to loop through the results. Is it possible in one loop?



Thank you in advance!


More From » dom

 Answers
58

Seems like you can use the same Array.prototype.slice.call that makes the args array-like object become an array. (See here)



var inputs = document.getElementsByTagName('input');
var selects = document.getElementsByTagName('select');

inputs = Array.prototype.slice.call(inputs);
selects = Array.prototype.slice.call(selects);

var res = inputs.concat(selects);

alert(res.length);

[#99449] Friday, May 22, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
manuel

Total Points: 747
Total Questions: 96
Total Answers: 95

Location: Argentina
Member since Thu, Mar 18, 2021
3 Years ago
manuel questions
Sat, Mar 28, 20, 00:00, 4 Years ago
Fri, Jan 17, 20, 00:00, 4 Years ago
Sun, Jun 30, 19, 00:00, 5 Years ago
Sat, Jun 15, 19, 00:00, 5 Years ago
;