jquery - Javascript to compare page you are on with a link -
i have menu, , need link current page on highlighted differently. twisted way of comparing strings now, sure there smarter way?
jquery(document).ready (function(){ jquery(".filteroptions .option").each (function (index,ele) { link=jquery(ele).find("a").attr("href").tostring(); p=jquery(window).attr("location").tostring().search(link) if (p!=-1){ jquery(ele).find(".link").addclass("current") } }); });
something work...
$('a').each(function(){ if ( $(this).attr('href') == window.location.href ) { $(this).addclass('current'); } });
or if you're not using full-path urls in links...
$('a').each(function(){ if ( window.location.href.indexof( $(this).attr('href') ) !== -1 ) { $(this).addclass('current'); } });
Comments
Post a Comment