0

我有一个 div 有两个类:

<div class="content pager" style="width: 1156px; float: left; list-style: none outside none;"></div>

我想用 jQuery 改变元素样式:

$(".content pager").width(0);  //Change the element style width 

但它不起作用。它有什么问题?

4

3 回答 3

6

试试这个:

$(".content.pager").width(0);

检查jQuery 的 类选择器

width(0)不会隐藏其内容。你需要hide它。而不是width(0). 所以,你可以试试这个:

$(".content.pager").hide(0); // Will hide the div and free its space.
$(".content.pager").css('visibility', 'hidden'); // Will hide the div and take space belongs to it.
于 2012-05-24T17:51:10.523 回答
1

另一种选择是 jQuery 的.filter方法。基本上,您搜索一个类,然后按另一个过滤选择。不过,对于您的特殊需求, $(".class1.class2") 应该就足够了。.filter 示例:

<div class="foo bar">div1</div>
<div class="foo">div2</div>
<div class="bar">div3</div>
​
$(".foo").filter(".bar").css('background-color', 'red');​

小提琴

于 2012-05-24T18:07:09.977 回答
0

试试这个:

$(".content").filter(".pager").width(0);

但是codeparadox 的解决方案也应该有效。

于 2012-05-24T17:54:43.397 回答