Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
78
rated 0 times [  83] [ 5]  / answers: 1 / hits: 22322  / 15 Years ago, tue, february 16, 2010, 12:00:00

I have a repeating table where the name of the elements would be (e.g. 'tdName_1' 'tdName_2'), and I was wondering if it would be possible to getElementsByName('tdName_').



PS: I can not use Jquery.



Thanks In advance.



Cesar.


More From » html

 Answers
8

This is not possible. I'm assuming for the rest of this answer that the elements you're interested in are <td>s. If so, then you should be aware that the name attribute is not valid for <td> elements.



You will have to create a list of matching elements manually. If you decide to use the name attribute anyway (instead of, say, adding a class in the class attribute), something like the following will work:



var table = document.getElementById(your_table_id);
var tds = table.getElementsByTagName(td);
var matchingTds = [];

for (var i = 0, len = tds.length, td, tdName; i < len; ++i) {
td = tds[i];
tdName = td.getAttribute(name);
if (tdName && tdName.indexOf(tdName_) == 0) {
matchingTds.push(td);
}
}

[#97560] Friday, February 12, 2010, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ryankiah

Total Points: 183
Total Questions: 99
Total Answers: 112

Location: Christmas Island
Member since Mon, Oct 19, 2020
4 Years ago
;