jQuery选择不适用于多行链接

时间:2018-08-08 15:46:48

标签: jquery css

我有一些段落是链接,我希望我的Jquery行为在整个段落上触发。 HTML来自this page

<ul id="search-results">
  <li>
    <a href="http://newsite.paulwagenblast.com/loveadorned/">Love Adorned ... Branding and identity development for concept lifestyle shop. Over two years, directly managed full cycle of <span class="search-excerpt">visual</span> identity and brand development of luxury lifestyle boutique from inception of retail...</a>
  </li>
</ul>

只要光标不在HTML的li或a上方,我都希望它是X。我尝试使用jQuery选择不是li的任何内容,而不是#searchresults li,但是当光标在链接的文本之间移动时,它会变回X。我希望当光标在li上的任何位置移动时,它是手形链接光标。我的jQuery在这里:

jQuery("body").hover( 

    function(a) {
    if ( jQuery(a.target).is(':not("#searchresults li")' ))
       {
            // Anywhere on the page that is not #searchresults li turn to the X cursor:
            jQuery("body").css("cursor", "url(http://paulwagenblast.com/newsite/wp-content/themes/blankslate/assets/PWDS_WEB_X.png) 25 25, pointer");   
       }

        }, function() {
            // Anywhere on the page that is #searchresults li, be the regular cursor
           jQuery("body").css("cursor", "default");

        }

    );

您能推荐一种更好的选择方法吗,以便当鼠标移到链接的段落上时,光标不会变回大X吗?

1 个答案:

答案 0 :(得分:0)

更改此行:

if ( jQuery(a.target).is(':not("#searchresults li")' ))

为此:

//Add the link(s) inside the li as well to the condition so the cursor doesn't change to an X
if ( jQuery(a.target).is(':not("#searchresults li")' && jQuery(a.target).is(':not("#searchresults li a")') ))