views:

173

answers:

3

I have an element that has two classes at all times:

<p class="general_description laptop">
<p class="images laptop">
<p class="specs laptop">

One class describes the item (laptop) and the other (general_description, images, specs) describes the state that the page needs to be in to present one of three types of information about the item.

How can I show or hide the <p> element only if both classes in my selector are present?

For example, if I only want to show the <p> element that corresponds to both the specs and laptop classes, I have tried doing this but it does not work:

$(".specs .laptop").show();
+4  A: 

$(".specs.laptop").show();

OR

you could use the is() function in jquery. it takes a selector and tells you if the element conforms to it:

$(".specs").is(".laptop"); //returns true if the element has the laptop class
Darko Z
Are you sure that $('.specs.laptop') selector will work?
SolutionYogi
It will definitely work. It is a standard CSS 2 selector that has been fully supported by jQuery for, almost, ever.
jason
See http://docs.jquery.com/Selectors/class#classclass if you do not believe.
jason
+1  A: 

IIRC, it is:

$(".specs").filter(".laptop").show()
gahooa
+1  A: 

Get rid of the space between the class names.

$(".specs.laptop").show();

Reference: jQuery

Joe Chung
Thx, I never realize this statement.
xandy