tags:

views:

62

answers:

3

i m creating td in javascript what i want is this "<td id='abc'>" how can i set the td id in javascript i use setAtteribute() not working

my code look like this

var cell4 = row.insertCell(3);
             cell4.innerHTML = "Song";
     var cell5 = row.insertCell(4);
     cell5.setAttribute('id','example1'); 

i want to set id of the td with value example plz help

A: 
cell5.attr("id","example1"); //jquery 
Chris
That wouldn't work, as cell5 is not a jQuery object. The original poster also doesn't appear to be using jQuery, but plain JavaScript.
Mario Menger
A: 

Using javascript (w/o jquery)

        cell4.id="some_td_id"

for example

        advTable=document.getElementById("advance_option");
        advRow = advTable.insertRow(advTable.rows.length);
        advRow.id ="tr_id"  // Here you can set tr's id
        cell0=advRow.insertCell(0);
        cell0.id="td_id"  // Here you can set td's id
    cell1=advRow.insertCell(1);
Salil
+2  A: 

cell5.id = 'example1'; // javascript

I suppose we're talking about IE here? I don't know about "id", but..

http://webbugtrack.blogspot.com/2007/08/bug-242-setattribute-doesnt-always-work.html

Marco Mariani