javascript - Add class active to menu links is working with links that has no extension only, how to make it find all links with and without extinctions? -


using .httaccess removed .php extensions end of url, example index.php shown index "site.com/index , not site.com/index.php".

now, using script below, adding class of .active anchor of current open page.

//main menu .active classes handler     $("#mainmenu a").filter(function () {         var _href = location.href.replace(/#.*/, "");         if (location.pathname === "/") {_href += "index";}         return _href === this.href;     }).addclass("active"); 

the problem is? script above try , find page names/url without php extension, example, links have follows in order work:

<li><a href="index">home</a></li> 

but links follows, , don't want remove .php extension

<li><a href="index.php">home</a></li>  

what can make find urls php or without? tried adding .php var _href = location.href.replace(/#.*/, ""); thinking way it, did not work. ideas?

you use regular expression retrieve value of , without extension. @ http://www.w3schools.com/jsref/jsref_obj_regexp.asp or learn @ http://regexone.com

you following.

var url = window.location.pathname; var filename = url.substring(url.lastindexof('/')+1); alert(filename); 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -