Javascript Jquery将CSS应用于动态创建的表行

Javascript Jquery将CSS应用于动态创建的表行,javascript,jquery,html,css,html-table,Javascript,Jquery,Html,Css,Html Table,我有一个HTML表,其中的行是使用Jquery动态生成的。行创建得很好,动态生成的ID工作得很好。 我想调整每次生成的表格单元格的宽度 <table border='1' id='foresttable'> <tr> <td id='addforestcell'><img id='addforestimg' src='img/addsign.png'

我有一个HTML表,其中的行是使用Jquery动态生成的。行创建得很好,动态生成的ID工作得很好。 我想调整每次生成的表格单元格的宽度

<table border='1' id='foresttable'>
                        <tr>
                            <td id='addforestcell'><img id='addforestimg' src='img/addsign.png' onclick="forestrotate()"></td>
                            <td></td>
                        </tr>
                        <tr>
                            <td>Forest Area #1</td>
                            <td><img src='img/cancel.png' href="#" title='Start Over' onclick="clearForest();" class='deletebtn'> Place a Forest/Group of Trees on the Map</td>
                        </tr>
                    </table>
我已经尝试对创建的每一行(.forestcol2)应用一个类,正如您在上面看到的,它在创建行时有效,但在更改最后一个元素时无效? 我也尝试过:

$(".forestcol2").css("width", 800);
但是没有运气


如果您能提供任何帮助,我将不胜感激。

我注意到您在js中编写了以下代码

tr:nth-last-child(2)
它选择了表的最后一个元素tr。它很有用,对吗?你不需要知道这里的id是什么,只需要知道位置

你知道,css也支持类似的特性。对于您的需求,它应该是这样的

#foresttable tr:nth-last-child(2){
 // any properties you want here
}
更多功能请在数小时后访问

这不是css或JQuery,它们工作得很好。 在使用Chrome开发者工具后,我可以看到它们被成功地应用了,但有什么东西正在覆盖它们,并将宽度设置为68px,或者其他样式的东西

我花了大约4个小时的时间在所有的东西中寻找问题的原因,但是没有运气

由于程序有几千行长,不值得进一步挖掘,我只想使用动态ID

但感谢所有回答/评论的人。

试试
tbl.find(“.forestcol2”).css(“width”,800)
tr:nth-last-child(2)
#foresttable tr:nth-last-child(2){
 // any properties you want here
}