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');
});
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>
© 2024 OneMinuteCode. All rights reserved.