简体   繁体   English

如何隐藏具有特定href的特定类的所有链接

[英]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. 我正在寻找一种在页面加载时隐藏href等于“ href1”或“ href2”或“ href3”的类“ checkme”的所有链接的方法。

Any javascript or jQuery sollution for this? 为此任何JavaScript或jQuery的解决方案?

You can do it with CSS: 您可以使用CSS来做到这一点:

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

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

http://jsfiddle.net/78zrnnvz/ http://jsfiddle.net/78zrnnvz/

I appreciate you asked for a js/jq solution, but it seems unnecessary in this situation 非常感谢您要求使用js / jq解决方案,但在这种情况下似乎没有必要

Just some upgrade to CSS solution by ilovecode: 只需通过ilovecode升级到CSS解决方案即可:

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

This will hide all links, that contain href1 or href2. 这将隐藏所有包含href1或href2的链接。 So it will hide href="http://href1" and href="href1" and href="http://www.href1" 因此它将隐藏href =“ http:// href1”和href =“ href1”和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”,然后添加以下CSS隐藏链接。

.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. 然后,您可以切换该类或其他类似的类,以隐藏和显示带有嵌套容器的内容,而不会产生很大的jquery。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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