I’ve been getting into jQuery again and obviously I’m missing something.
I want to add a class to an element depending on if another one is visible.
It’s hidden with display: none; and activated with slideToggle
I have this:
if ($("#about_me").is(':visible')){
$("#about_me_clicker").addClass(".about_highlight");
} else {
}
Now I’m assuming I’ve gotten it totally wrong, so here’s a fiddle for you to see.
How can I add this class to the certain div, if the other one is :visible?
Thanks.
Edit:
To make things clear, I will be only applying the class to the one element.
Change:
To:
You don’t need to include the
.in the class names foraddClass.Also, in your fiddle’s CSS:
Should be:
Another note, in CSS, ids take precedence over classes. So even though the div has class
about_highlight, the color declared in#about_me_clickerwill be active.To fix this you can use
!important.To fix this, just make a more specific CSS rule.
Updated fiddle: http://jsfiddle.net/YVqJ7/20/