2
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=

2
  • 2
    The url of the page or the link? Commented Sep 9, 2011 at 16:04
  • The fact that he/she wants to hide an entire class if the "url contains.." would lead me to believe that it's the location.href not a.href, otherwise what would be the point of hiding an entire class of links if one contains said string. Commented Sep 9, 2011 at 16:10

4 Answers 4

3

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/

Sign up to request clarification or add additional context in comments.

Comments

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

2 Comments

I noticed that as soon as i posted it. check now.
concept is the same. Sorry, quick answer. :)
0

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

Comments

0

How about this

var url = window.location.pathname;


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

}

4 Comments

I'm very confused what this is supposed to do. Even with the quotes removed, it's not valid JS.
what url is returing, when you use "var url = window.location.pathname; "
Right, but your if condition has some issues. 1) It will always evaluate to true because it is a string literal, and therefore "truthy". 2) JavaScript doesn't have a contains method. 3) Even if JavaScript did have a contains method, you can't invoke it with a :. 4) If you were trying to use jQuery's contains pseudo-selector, it would need to be used in a selector context (e.g., $('.foo:contains(...)')), not to mention that :contains is only used for searching the tag body, not the href attribute.
The above comment feels like it came across snobbish, so sorry about that. I don't mean to be critical - just trying to understand the solution you provided.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.