0

I wanted to identify each html page separately to add active style like(.select). But I'm not sure how to get a page url in using JQuery..?

for example I want to give .select class to about.html page when someone going to click the about button.

Please help me, im looking forward to your valuable replies.

Thanks Paulson

1
  • Can you give more detail? Your question is confusing. Commented Nov 1, 2010 at 22:55

3 Answers 3

1

The best solution would be to maintain a different css stylesheet for each page, but if you have to do it dynamically.

document.location.href

Is the standard way to ge the URL, and is not jQuery specific.

Sign up to request clarification or add additional context in comments.

Comments

0

Do you have to use JavaScript to get the specific page? What I usually do is set a page variable on each page load. If you need to pass it through to the JavaScript/jQuery you cold then just create a new variable inside of a tag. Hope that helps!

Comments

0

You could try something like this:

var page = location.pathname;

$('a[href$=' + page + ']').addClass('select');

This gets the pathname portion of the URL, then uses the attribute ends with selector to find <a> elements that that have an href attribute that ends with the current path, and the .addClass() method to add the select class.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.