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
$(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.