开发者

Is there a way to access an array of col tags for a table in javascript?

I have a table that looks like:

<table id="myTable">
    <col id="name" />
    <col id="birthYear" />
    <col id="phone" />
    <td>
        <tr>Joe</tr>
        <tr>1972</tr>
        <tr>202-555-1234</tr>
    </td>
</table>

Is there an easy way to get an开发者_开发技巧 array of the <col /> tags? I don't want to use getElementById because I don't know the ids of the col tags, although I will know the Id of the table. I don't want to use getElementsByTagName because there will be several tables in the document with col tags.

I'm not using jquery, just regular javascript.

Any ideas?


getElementsByTagName can be used on table with id "myTable" : it will returns all col of this table.

here is an example :

document.getElementById("myTable").getElementsByTagName("col")


Javascript supports XPath:

document.evaluate('//col', document.getElementById('myTable'));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜