tags:

views:

69

answers:

2

Losing my mind on this one..

How can I do something as simple as..

If div has class "something" then make div#test have a class of "awesome"

<div class="something">hey there</div>

<div id="test">Am I awesome?</div>

Much Thanks!

+2  A: 

Try this:

if ($("div.something").length) {
    $("div#test").addClass("awesome");
}
Gumbo
Note that this will add the awesome class if there is one (or more) DIVs on the page with the "something" CSS class.
Bernhard Hofmann
Makes Sense. If there is more than one div with the class name. Thanks!
Bruno
A: 

If you want to check the class of a particular div, then change your html

<div id="im_special" class="something">hey there</div>

and then look for the id in the javascript

if ($("div#im_special.something").length) {
    $("div#test").addClass("awesome");
}
Tom Leys