开发者

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 c开发者_Python百科an be accomplished 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 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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜