1

I have an URL like this:

http://mysite.com/something/view/something-else/

I want to hide all the images with the class .attachment inside all the pages that have the /view/ part in the URL using jQuery.

Any suggestions to accomplish this?

1 Answer 1

2

It would be something like this

var url = window.location.pathname;

if(url.indexOf('/view/') >= 0){
    $('.attachment').css('display','none');
}

Here is an example... you need to click Run to see it work.

http://jsfiddle.net/jasongennaro/rAkGS/

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

3 Comments

I think you want url.indexOf('/view/') >= 0 since '/view/' can be at the beginning of the pathname so indexOf() could find it and return 0.
or url.indexOf('/view/') != -1
I guess I could have used url.indexOf('/view/') != -1 as well.

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.