rufusv141exe
rufusv141exe.
Q:
JavaScript function for adding active class to navigation
I am trying to make a JavaScript function to add an active class to the navigation that has a class of nav__main.
However, I can't get the code to work. I think I am missing something obvious here.
Any ideas?
function activeNav(){
$('nav__main').addClass('nav__main-active');
}
A:
Your syntax is wrong:
$('nav__main').addClass('nav__main-active');
It should be like:
$('nav__main').addClass('nav__main-active');
If you need to call it, use.trigger('click'):
$('nav__main').addClass('nav__main-active').trigger('click');
Demo:
function activeNav() {
$('nav__main').addClass('nav__main-active');
}
activeNav();
.nav__main-active {
color: #fff;
background-color: #555;
border-color: #333;
}
page one
page two
Note that you need to add classes to the elements as well:
page one
Swiss police arrest woman in Norbert Niers' murder Published duration 11 June 2013
image caption The suspect, who remains in custody, is accused of killing Norbert Niers (right)
Swiss police have arrested a 35-year- ac619d1d87
Related links:
Comments