最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html table - how to set an id with some value in of td in javascript - Stack Overflow

programmeradmin0浏览0评论

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

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

Share Improve this question edited Jul 27, 2010 at 10:42 kennytm 524k110 gold badges1.1k silver badges1k bronze badges asked Jul 27, 2010 at 10:40 user403269user403269 912 gold badges2 silver badges3 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

cell5.id = 'example1'; // javascript

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

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

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);
cell5.attr("id","example1"); //jquery 
发布评论

评论列表(0)

  1. 暂无评论