user472285
user472285

Reputation: 2674

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=

Upvotes: 2

Views: 7739

Answers (4)

Meenakshi
Meenakshi

Reputation: 121

How about this

var url = window.location.pathname;


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

}

Upvotes: 0

Jeff B
Jeff B

Reputation: 30099

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/

Upvotes: 3

Mohsen
Mohsen

Reputation: 65785

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()

Upvotes: 0

rlemon
rlemon

Reputation: 17666

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

Upvotes: 1

Related Questions