faqts : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

5 of 10 people (50%) answered Yes
Recently 5 of 10 people (50%) answered Yes

Entry

getAttribute("id") does not return values on dynamically created table rows

Apr 8th, 2008 19:05
ha mo, Dave Clark, windi wee,


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Windi,
     The first question is whether an ID value was assigned to the 
dynamically-created table row in the first place.  Then, rather than 
try to use getAttribute(), just check the object directly:
var tbl = document.getElementById("tableId");
var rows = tbl.rows;
var x, len = rows.length;
for (x=0; x<len; ++x)
{
    if(rows[x].id
    && !/^\s*$/.test(rows[x].id))
        alert("Row " + (x+1) + " has '" + rows[x].id + "' id value.");
    else
        alert("Row " + (x+1) + " has no id value.");
}
Take care,
Dave Clark
www.DaveClarkConsulting.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com