开发者

Using JQuery to Hide links based on URL value

jQuery(".rfr-col-title").css("display", "none");

I would like to hide this class .rfr-col-title if the url contains abc/Lists/abc/DispForm.aspx?ID=

http://w开发者_如何学Cin-e98sopqc735/abc/Lists/abc/DispForm.aspx?ID=


The jQuery way would be to do an attribute selector:

$('a[href*="abc/Lists/abc/DispForm.aspx?ID="]').hide();

The *= means "contains".

You could also use ^= for "begins with" or $= for "ends with".

Example: http://jsfiddle.net/dQFJe/

Attribute selector docs: http://api.jquery.com/category/selectors/attribute-selectors/

Edit

I just reread the question. Are you talking about the url of the page? If so, you have to do an if statement on a window location match:

if(window.location.href.match("abc/Lists/abc/DispForm.aspx?ID=")) {
    $(".rfr-col-title").hide();
}

Example: http://jsfiddle.net/EyVr4/


if(window.location.href.indexOf("abc/Lists/abc/DispForm.aspx?ID=") > -1) {
  jQuery(".rfr-col-title").hide();
}


jQuery do have a attribute contain selector. So you can do this:

$('a[href*="abc/Lists/abc/DispForm.aspx?ID="]').hide();

Instead of .css('display', 'none') use .hide()


How about this

var url = window.location.pathname;


if ("url:contains('abc/Lists/abc/DispForm.aspx?ID=')"){
    $(".rfr-col-title").hide();

}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜