jQuery addClass table issue
jQuery addClass table issue
我有一个使用datatablesjQuery插件的表。
我有以下css,使最后一列适合文本:
#products tr td:last-child {
width: 1%;
white-space: nowrap;
}
这非常有效。然而,我正试图在最后两列中做到这一点,为了跨浏览器,我正尝试复制jQuery中的功能。
我有以下内容:
.fitTableLinks{
width:1%;
white-space:nowrap;
}
jQuery是:
$("#products tr td:last-child").addClass("fitTableLinks");
但这不起作用,但没有任何控制台错误?
谢谢你的帮助!
我同意CSS可能是Salman A上面提到的处理它的最佳方式。如果你想使用jQuery,我想你必须为每个tr.运行你的代码
$("#products tr").each(function() {
var $this = $(this);
$this.find('td:last-child').addClass("fitTableLinks");
});
如果最后两列需要它,只需检查$this.children()的长度即可
$("#products tr").each(function() {
var $this = $(this);
var secondToLast = $this.children().length - 2;
$this.find('td:last-child').addClass("fitTableLinks");
$this.find('td').eq(secondToLast).addClass("fitTableLinks");
});
相关文章:
- issue with FB.Event.subscribe
- Jquery - table.row(tr) is undefined
- 使用Jquery Issue垂直重新排序Divs
- 创建了一个选项卡,但点击时不会起作用-jQuery issue/newbie
- javascript, ajax, table, colour
- jQuery parent() in table
- jQuery find() Issue
- $route.reload(); Issue
- click-cell.bs.table是如何工作的
- PHP json_encode issue
- Three.js issue creating meshes outside of loader's load(
- Jquery :gt(value) issue
- pickaday maxDate issue
- onclick for table TD
- Stage.load(json) Issue..Kinetic.js
- Mootools Selector issue
- ng-repeat issue and html table
- Jquery lazyload plugin and html table issue
- Knockout with HTML table issue
- jQuery addClass table issue