javascript - Switch Navigation Classes When Clicking on None-Nav Element -
i have navigation gives current class , loads content based on file is
$('nav a').on('click', function(e) { // click on nav e.preventdefault(); // prevent loading var url = this.href; // url load $('nav a.current').removeclass('current'); // update nav $(this).addclass('current'); $('#container').remove(); // remove old part $('#content').load(url + ' #container').hide().fadein('slow'); });
problem being on 1 of pages have 'learn more' link function exact same way, can't use this
addclass('current')
need find way.
i tried using if/else statement haven't found way make work.
$('.first a').on('click', function(e) { e.preventdefault(); var url = this.href; $('nav a.current').removeclass('current'); if(url == '../jq-load2.html') { $('nav a:nth-of-type(2)').addclass('current'); $('#container').remove(); // remove old part $('#content').load(url + ' #container').hide().fadein('slow'); } else if(url == '../jq-load3.html') { $('nav a:nth-of-type(3)').addclass('current'); $('#container').remove(); // remove old part $('#content').load(url + ' #container').hide().fadein('slow'); } else { $('nav a:nth-of-type(4)').addclass('current'); $('#container').remove(); // remove old part $('#content').load(url + ' #container').hide().fadein('slow'); } });
i realize problem lies here if(url == '../jq-load2.html'
because computer seeing ../jq-load2.html
string instead of checking file directory ../
in css. how can fix this?
Comments
Post a Comment