Add Class To Regex Jquery
I have this if( window.location.href == 'http://localhost:3000/categories') { $('#container ul #all_categories a.categories-menu').css('font-weight','bold'); } }); but
Solution 1:
You don't need a RegEx. The following method is easier, and is also easier to maintain (you don't have to change the URL in the code when moving the page to the production environment):
location.pathname.indexOf('/boards', 1) !== -1
The previous would also match /me/not/boards
. If you don't want that:
var index = location.pathname.indexOf('/boards', 1);
index !== -1 && location.pathname.lastIndexOf('/', index-1) === 0
Finally, the RegEx method:
/^\/[^/]+\/boards/.test(location.pathname)
Implementation example
if( /^\/[^/]+\/boards/.test(location.pathname) ) {
$("#container ul #all_categories a.categories-menu").css("font-weight","bold");
}
});
Post a Comment for "Add Class To Regex Jquery"