Original post: Why doesn't this simple script work?
if ($('#navigation > ul > li > ul > li > a').hasClass('.active')) {
$(this).parent().parent().parent().addClass(".active");
}
EDIT:
This won't hide the H1:
if ($('#content h1').hasClass('aktiv')) {
$(this).hide();
}
Only this will:
if ($('#content h1').hasClass('aktiv')) {
$('#content h1').hide();
}
Why can't I use the (this)?
The dot is not part of the class name. It's only used in CSS/jQuery selector notation. Try this instead:
if ($('#navigation a').hasClass('active')) {
$(this).parent().addClass('active');
}
If $(this)
refers to that anchor, you have to change it to $('#navigation a')
as well because the if condition does not have jQuery callback scope.
Alternatively you could use:
if ($('#navigation a').is(".active")) {
$(this).parent().addClass("active");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With