Check out my example here: http://timkjaerlange.com/foobar/test.html
I'm currently trying to apply a class to a header based on the visibility of a div on the page.
This is my markup:
<a href="#">Toggle visibility!</a>
<div></div>
<h1 class="one">If the box is hidden this headline should be italic.</h1>
<h1 class="two">If the box is visible this headline should be italic.</h1>
And these are the classes that are in play:
.hideIt {
display: none;
}
.ifHidden {
font-style: italic;
}
.ifVisible {
font-weight: italic;
}
jQuery adds the behaviour:
$('a').click(function() {
$('div').toggleClass('hideIt');
if ( $('div').is(':hidden') ) {
$('h1.one').addClass('ifHidden');
$('h1.one').removeClass('ifVisible')
}
if ( $('div').is(':visible') ) {
$('h1.two').addClass('ifVisible');
$('h1.two').removeClass('ifHidden');
}
});
Initially it works, when I click the anchor, h1.one is italized, however when I click again nothing happens. I'm somewhat of a Javascript, jQuery n00b, so any hint of what could be wrong is highly appreciated!