Insert th in thead

后端 未结 4 1883
时光取名叫无心
时光取名叫无心 2021-02-01 16:15

I want to insert a th tag inside tr of thead element of a table. I am using insertCell method of row object created under

4条回答
  •  孤街浪徒
    2021-02-01 16:31

    You can also use the insertCell method as originally requested. You just have to change the outerHTML to overwrite the created by the insertCell method:

    var table = document.createElement("TABLE")
    var row   = table.insertRow(0);
        row.insertCell(0).outerHTML = "First";  // rather than innerHTML
    

    To match the example given:

    HTML

    First

    Javascript

    var tr = document.getElementById('table').tHead.children[0];
        tr.insertCell(1).outerHTML = "Second"  // some browsers require the index parm -- 1
    

提交回复
热议问题