Find out what page I'm on

I need to find out what page I am on, then hide a div based on the result.
LVL 5
Tom KnowltonWeb developerAsked:
Who is Participating?
 
HainKurtConnect With a Mentor Sr. System AnalystCommented:
try:

if ($(location).attr("href")=="some page") $("#some_div").show();
0
 
HainKurtSr. System AnalystCommented:
also you can try these

$(location).attr("pathname")
window.location
window.location.href

0
 
mwochnickCommented:
to find the path
var pathname = window.location.pathname;

JQuery API documentation on how to hide an element with example code
http://api.jquery.com/hide/
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
Tom KnowltonWeb developerAuthor Commented:
Can I modify this to see if the location href contains a substring or not?

if ($(location).attr("href")        *=         "some substring") $("#some_div").show();
0
 
mwochnickCommented:
btw $(location) is not supported, but lots of people use it - http://bugs.jquery.com/ticket/7858
0
 
Tom KnowltonWeb developerAuthor Commented:
Perfect.

notes for myself on this solution:

if ($(location).attr("href").indexOf("Book") != -1)
        {
            $('#catalog_name').hide();
        }

Open in new window

0
 
Tom KnowltonWeb developerAuthor Commented:
More notes:

It seems this is better:


 var loc = window.location.href;
        if (loc.indexOf("Book") != -1)
        {
            $('#catalog_name').hide();
        }
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.