I am using jQuery currently and I am looking for a way to hide if the url contains /blah/.
Thanks in advance for your help. I am a js Noob and know it can be acplished with regex somehow but don't have the time to learn this right now. I have a deadline I need to meet!
Thanks, Jack
I am using jQuery currently and I am looking for a way to hide if the url contains /blah/.
Thanks in advance for your help. I am a js Noob and know it can be acplished with regex somehow but don't have the time to learn this right now. I have a deadline I need to meet!
Thanks, Jack
Share Improve this question edited Nov 23, 2009 at 12:14 Justin Johnson 31.3k7 gold badges66 silver badges89 bronze badges asked Nov 19, 2009 at 2:44 JacksonJackson 1,1843 gold badges17 silver badges27 bronze badges 2-
What are you wanting to hide? An
a
element whosehref=
matches a url? Or are you looking to hide an element on the page if the page's url matches? – Doug Neiner Commented Nov 19, 2009 at 2:46 - 2 hide...what? A div? The entire page? Do you want notified so you can hide yourself in a closet...? – Michael Haren Commented Nov 19, 2009 at 2:46
3 Answers
Reset to default 6I think he wants to hide an element if the URL contains that part.
if (/\/blah\//.test(window.location)) {
$('#element').hide();
}
Sure, here you go:
Hide 'my_other_id' if the url contains 'foo'
if ($('a[href*=foo']).size() > 0) $('#my_other_id').hide();
If you want to do this when the page loads, use this:
$(document).ready( function() {
if ($('a[href*=foo']).size() > 0) {
$('#my_other_id').hide();
}
});
Hi Everyone and thank you for your responses. For some reason it did not save my whole message..... Weird!
The full version went more like this:
Hi Folks,
I am using jQuery currently and I am looking for a way to hide an element if the url contains /blah/.
if the url contains /foo/ addClass to <div id="blah"></div> so the class is added like <div id="blah newclass"></div> then I can write css for .newclass {display:none;}
I hope this makes more sense. I'm going to hop in and try your suggestions now. THANK YOU!