3

I have a site I'm working on. I need to be able to perform a specific function if the URL matches a specific URL. Here's an example of what I'm trying to do:

If the URL matches this URL:

http://www.example.com/EIFS-items/search.php?l2=3,15,25

then I want to have jQuery add a class of "show" to the div with the class of "content" below.

Is this possible?

<html>
<head>
<title>Title</title>
<style type="text/css">
.content {
display: none;
}
.show {
display: block;
}
</style>
</head>
<body>
<div class="content">
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
</div><!-- end .content -->
</body>
</html>
1
  • check against document.location once the page is loaded and apply the CSS that way i would presume Commented Jan 6, 2011 at 20:42

3 Answers 3

8
var url = "http://www.example.com/EIFS-items/search.php?l2=3,15,25";
$(function(){
  if (location.href==url){
    $('.content').show();
  }
});
Sign up to request clarification or add additional context in comments.

1 Comment

sweet...that did the trick...thanks so much! I just changed the jQuery to have ".content" instead of "#content". thnx again!
2

You seem to be looking for the location object, which contains information about the URL of the current page.

Comments

1

Probably will be better to use the querystring location.search than location.href. This would cover subdomains/protocol changes.

if(location.search == "?l2=3,15,25")
    $('.content').addClass('show');

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.