排除jquery中访问/悬停效果的徽标部分
我在下面有一个用于导航的静态代码排除jquery中访问/悬停效果的徽标部分,jquery,html,Jquery,Html,我在下面有一个用于导航的静态代码 <div class="nav__show-hide--800 step-asia__grid"> <div class="step-asia__grid-12--col-5"> <div class="nav__left"> <a href="http://localhost/step-asia/about.php">About Us</a> <a href=
<div class="nav__show-hide--800 step-asia__grid">
<div class="step-asia__grid-12--col-5">
<div class="nav__left">
<a href="http://localhost/step-asia/about.php">About Us</a>
<a href="http://localhost/step-asia/whatwedo.php">What We Do</a>
</div>
</div>
<div class="step-asia__grid-12--col-2">
<div class="nav__logo nav__logo--height">
<a href="http://localhost/step-asia/" id="logo"><img src="assets/image/logo-1.png" alt="Step Asia Logo"></a>
</div>
</div>
<div class="step-asia__grid-12--col-5">
<div class="nav__right">
<a href="http://localhost/step-asia/how-it-works.php">How It Works</a>
<a href="http://localhost/step-asia/contact.php">Contact Us</a>
</div>
</div>
</div>
但我想排除这一部分
<a href="http://localhost/step-asia/" id="logo"><img src="assets/image/logo-1.png" alt="Step Asia Logo"></a>
有更好的办法吗?使用.not()
从选择器中排除特定元素
$("[href]").not("#logo").each(function() {
if ($(this).attr("href") === window.location.href) {
$(this).addClass("active");
}
});
或者最终代替.not()
或:not()
您可以直接进入if:
这可以使用简单的css来完成。 就你而言:
.active #logo:hover{
text-decoration:none !important;
}
您可以将活动类添加到徽标,但这将覆盖该徽标。您也可以使用$(this.attr(“href”)
而不是this.href
,因为它会给出不同的结果。仅仅是因为this.href
!=this.getAttribute(“href”)
if (this.id !== "logo" && this.getAttribute("href") === window.location.href) {
.active #logo:hover{
text-decoration:none !important;
}