I want to put out a border when I mouse hover on jQuery.

Asked 2 years ago, Updated 2 years ago, 449 views

I want to put a border on the span tag when I hover, but it doesn't work.
What should I do to make it work?

<ul class="nav">
  <class="nav-item">a class="navbar-link" href="/xxx.html">span class="linear">xxx;/span><a>li>;
  <class="nav-item">a class="navbar-link" href="/xxx.html">span class="linear">xxx;/span><a>li>;
</ul>



$(".nav-item").hover(function(){
      $("this").find('span').css('border-bottom','1px solid#fff');
    }, function(){
      $("this").find('span').css('border-bottom','1px solid#ccc');
    });

javascript html jquery

2022-09-30 21:54

1 Answers

This is not text, but
The this keyword.
So don't double-quote it.

$(".nav-item").hover(function(){
      $(this).find('span').css('border-bottom','1px solid#fff');
    }, function(){
      $(this).find('span').css('border-bottom','1px solid#ccc');
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul class="nav">
  <class="nav-item">a class="navbar-link" href="/xxx.html">span class="linear">xxx;/span><a>li>;
  <class="nav-item">a class="navbar-link" href="/xxx.html">span class="linear">xxx;/span><a>li>;
</ul>


2022-09-30 21:54

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.