0

I have an unordered list <ul> with links in it <a> and I'd like to animate certain parts of text depending on which one of listings is hovered. I made it work like below but this snippet seems oddly inefficient:

$( "a#a1" )
  .mouseover(function() {
    $( "span#span1" ).addClass('animated rubberBand');
  })
  .mouseout(function() {
    $( "span#span1" ).removeClass('animated rubberBand');
  });
$( "a#a2" )
  .mouseover(function() {
    $( "span#span2" ).addClass('animated rubberBand');
  })
  .mouseout(function() {
    $( "span#span2" ).removeClass('animated rubberBand');
  });
$( "a#a3" )
  .mouseover(function() {
    $( "span#span3" ).addClass('animated rubberBand');
  })
  .mouseout(function() {
    $( "span#span3" ).removeClass('animated rubberBand');
  });

etc...

HTML:

<ul class="display-posts">
    <li class="listing-item"><a class="titledp" id="a1" href="">
    <span id="span1" class="fa fa-angle-right arrowkariera"></span>POST1</a></li>
    
    <li class="listing-item"><a class="titledp" id="a2" href=""><span id="span2" class="fa fa-angle-right arrowkariera"></span>POST2</a></li>
    
    <li class="listing-item"><a class="titledp" id="a3" href=""><span id="span3" class="fa fa-angle-right arrowkariera"></span>POST3</a></li>
    
    <li class="listing-item"><a class="titledp" id="a4" href=""><span id="span4" class="fa fa-angle-right arrowkariera"></span>POST4</a></li>
    
    <li class="listing-item"><a class="titledp" id="a5" href=""><span id="span5" class="fa fa-angle-right arrowkariera"></span>POST5</a></li>
    
    <li class="listing-item"><a class="titledp" id="a6" href=""><span id="span6" class="fa fa-angle-right arrowkariera"></span>POST6</a></li>
    
    <li class="listing-item"><a class="titledp" id="a7" href=""><span id="span7" class="fa fa-angle-right arrowkariera"></span>POST7</a></li>
</ul>

As you can see I need to carry on the number of anchor tags to the span selector because I want only that specific span to be animated on all of them.

zcoop98
  • 2,590
  • 1
  • 18
  • 31
Konrad Albrecht
  • 1,701
  • 1
  • 9
  • 20

0 Answers0