Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
排除jquery中访问/悬停效果的徽标部分_Jquery_Html - Fatal编程技术网

排除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;
}