Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Fa-Spin on hover link text too, not only when hover icon

$('.fa-spinner').hover(function() {
        $(this).addClass('fa-spin');
    }, function() {
        $(this).removeClass('fa-spin');
    });
<link href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.2.1/css/fontawesome.min.css" rel="stylesheet"/>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table class="table">
     <tr><td><a href=""><i class="fa fa-spinner"></i> Mylink 1</a></td></tr>
     <tr><td><a href=""><i class="fa fa-spinner"></i> Mylink 2</a></td></tr>
     <tr><td><a href=""><i class="fa fa-spinner"></i> Mylink 3</a></td></tr>
     <tr><td><a href=""><i class="fa fa-spinner"></i> Mylink 4</a></td></tr>
     <tr><td><a href=""><i class="fa fa-spinner"></i> Mylink 5</a></td></tr>
    </table>

i have code like this

<table class="table">
 <tr><td><a href=""><i class="fa fa-spinner"></i> Mylink 1</a></td></tr>
 <tr><td><a href=""><i class="fa fa-spinner"></i> Mylink 2</a></td></tr>
 <tr><td><a href=""><i class="fa fa-spinner"></i> Mylink 3</a></td></tr>
 <tr><td><a href=""><i class="fa fa-spinner"></i> Mylink 4</a></td></tr>
 <tr><td><a href=""><i class="fa fa-spinner"></i> Mylink 5</a></td></tr>
</table>

i want to add animation fa-spin when hover link with this juery code

$('.fa-spinner').hover(function() {
    $(this).addClass('fa-spin');
}, function() {
    $(this).removeClass('fa-spin');
});

the problem is it’s still lacking than what i intent
when i hover mouse on label text Mylink 1 etc,
it’s not add class fa-spin in <i> tag
it’s only add fa-spin when i hover mouse in fa-spinner icon

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

how should i do it properly?

>Solution :

You should write the function for links. To achieve that you can add classes to links then do:

<table class="table">
 <tr><td><a href="" class="fa-link"><i class="fa fa-spinner"></i> Mylink 1</a></td></tr>
 <tr><td><a href="" class="fa-link"><i class="fa fa-spinner"></i> Mylink 2</a></td></tr>
 <tr><td><a href="" class="fa-link"><i class="fa fa-spinner"></i> Mylink 3</a></td></tr>
 <tr><td><a href="" class="fa-link"><i class="fa fa-spinner"></i> Mylink 4</a></td></tr>
 <tr><td><a href="" class="fa-link"><i class="fa fa-spinner"></i> Mylink 5</a></td></tr>
</table>

Then your js code :

$('.fa-link').hover(function() {
    $(this).find(".fa-spinner").addClass('fa-spin');
}, function() {
    $(this).find(".fa-spinner").removeClass('fa-spin');
});
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading