Issue
I need to change the appearance of a link from a menu if it belongs to the current URL. I don't know how I can detect current URL and change a element class.
I would use jQuery
Solution
$( document).ready(function (){
$( function(){
var url = window.location.pathname,
urlRegExp = new RegExp(url.replace( /\/$/,'' ) + "$" );
$('a').each( function(){
if(urlRegExp.test(this .href.replace(/\/$/, ''))){
$( this).addClass('active' );
}
});
});
});
Answered By - mjimcua
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.