Jquery / Javascript - Show / Hide Id If Current Url Contains /foo/
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 accomplished with re
Solution 1:
I think he wants to hide an element if the URL contains that part.
if (/\/blah\//.test(window.location)) {
$('#element').hide();
}
Solution 2:
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();
}
});
Solution 3:
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!
Post a Comment for "Jquery / Javascript - Show / Hide Id If Current Url Contains /foo/"