boltan
boltan

Reputation: 11

How to show divs with specific class

I need to show only specific divs in aone page. I want to put all the divs in the page and that I will have a button that change which divs the browser shows every time.

This is my code:

<div class="all red">content..</div>
<div class="all blue">content..</div>
<div class="all red">content..</div>
<div class="all green">content..</div>
<div class="all blue">content..</div>

All stands for an option to show all the divs and every div has its own seperate class that I want choose.

Upvotes: 0

Views: 633

Answers (2)

i-mighty
i-mighty

Reputation: 33

Since you are using jQuery, it gets lot easier. Simply set the initial display of all the classes you want hidden to "none"

.red{
     display:none; 
}

And then set the display to block in your event handler function.

$(".red").css("display","block");

Hopefully that solves it.

Upvotes: 0

Pranay Rana
Pranay Rana

Reputation: 176934

you have to do like this , you have to use show() -for showing div, and hide()-for hiding div method of jquery

$("div.red").show();--this show red
$("div.blue").show();--this show blue
$("div.green").show();--this show green

Upvotes: 2

Related Questions