PDA

View Full Version : getElementById


diliphtml
07-09-2004, 03:59 PM
Hi

If I have multiple tags in my html page with ID starting with a specific string , Is there anyway to get all the tags ?

for example if have

<tr id='row1'>
<tr id='row2'>
<tr id='row3'>

Is there anyway to access all the <tr> where the id starts with "row"

TIA

agent002
07-09-2004, 04:19 PM
You could do it in a for loop:
for(var i = 1; i <= 3; i++){
document.getElementById('row'+i).appendChild(document.createTextNode('neeeeeeed pie!'));
}

diliphtml
07-09-2004, 04:28 PM
I could do that if i know the number of Id's I have?

The page is dynamically generated , so !!

agent002
07-09-2004, 04:44 PM
In that case...
var rows = document.getElementsByTagName('tr');
for(var i = 0; i < rows.length; i++){
if(rows[i].id.match(/^row\d+$/) != null){
rows[i].appendChild(document.createTextNode('neeeeeeed pie!'));
}
}