简体   繁体   中英

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://win-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();
}

How about this

var url = window.location.pathname;


if ("url:contains('abc/Lists/abc/DispForm.aspx?ID=')"){
    $(".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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM