0

I have a div with two classes:

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

I want to change the element style with jQuery:

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

but it doesn't work. What is wrong in it?

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Rorshak
  • 13
  • 2
  • possible duplicate of [jQuery multiple class selector](http://stackoverflow.com/questions/1041344/jquery-multiple-class-selector) – lonesomeday May 24 '12 at 17:52

3 Answers3

6

Try this:

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

Check jQuery's Class Selector.

width(0) will not hide its content. You need to hide it. Instead of width(0). So, you can try this:

$(".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.
thecodeparadox
  • 84,459
  • 21
  • 136
  • 161
1

Another alternative would be jQuery's .filter method. Basically you search for one class then filter the selection by another. For your particular needs $(".class1.class2") should be sufficient though. .filter example:

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

See fiddle.

AlexMA
  • 9,422
  • 7
  • 40
  • 58
0

Try this:

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

But thecodeparadox's solution should work too.

Community
  • 1
  • 1
Kris Ivanov
  • 10,078
  • 1
  • 21
  • 34