简体   繁体   中英

How to hide all links of specific class with specific href

I'm looking for a way to hide all links of class "checkme" that have href equal to "href1" OR "href2" OR "href3" on page load.

Any javascript or jQuery sollution for this?

You can do it with CSS:

a.checkme[href='href1'],
a.checkme[href='href2']
{
    display: none;
}

http://css-tricks.com/attribute-selectors/

http://jsfiddle.net/78zrnnvz/

I appreciate you asked for a js/jq solution, but it seems unnecessary in this situation

Just some upgrade to CSS solution by ilovecode:

a.checkme[href*='href1'],
a.checkme[href*='href2']
{
   display:none;
}

This will hide all links, that contain href1 or href2. So it will hide href="http://href1" and href="href1" and href="http://www.href1"

I would suggest creating a class, for example 'hide-links' and then add the following CSS to hide the links.

.hide-links [href="href1"], .hide-links [href="href2"], .hide-links [href="href3"] { ... }

You can then toggle that class, or other similar classes, to hide and show things with-in nested containers with out having a big mess of jquery.

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