0

referring to this question:

add class to regex jquery

I would like to know how to use this code for pages like http://www.mydomain.com or http://localhost/ or http://localhost:3000/ or any index page.

The code example is this for http://localhost/username/boards

if( /^\/[^/]+\/boards/.test(location.pathname) ) {
     $("#container ul #all_categories a.categories-menu").css("font-weight","bold");
}
3
  • You mean you want to do something when the pathname is empty? Test whether it is empty (or contains only /) ;) Commented Mar 3, 2012 at 10:50
  • Yes when The path name its empty or contain only / :D. I have window.location.href == "http://localhost:3000/" but it is difficult to maintain :( if I deploy the server in production mode with http://www.mydomain.com Commented Mar 3, 2012 at 11:03
  • 1
    Yeah, so if(location.pathname === '/') will work just fine. Commented Mar 3, 2012 at 11:08

1 Answer 1

0

Ok, lets make it official:

All you have to do is to test the URL for an empty path:

if(location.pathname === '/')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.