0

I have a loop in php which echo out these divs:

<div class="nyhed">
 <p class="nyheds_dato_p" style="color:#900;">'.$pub_date[1].'/'.$pub_date[2].'/'.$pub_date[0].'</p>
 <p class="nyhed_p">'.substr($teaser, 0, 55).'..</p>
 <a href="'.$url.'" class="nyheds_link">'.$link_navn.'</a>            
</div>';

When ever a link is hovered, i am adding an animation to change the background color of the div class="nyhed".

As it is now, all the divs are animated..How do i only add the jquery function the specific div class="nyhed" belonging to the link being hovered?

This is what i have:

$(document).ready(function(){
$(".nyheds_link").hover(function() {
$(".nyhed").animate({ backgroundColor: "#DDD" }, 800);},function() 
{
    $(".nyhed").animate({ backgroundColor: "#f5f5f5" }, 300);
});
});

Do I need to add: .each and then .find the parent class="nyhed"? And how can I achieve that....

All the best,

Klemme

Edited by klemme

1
Contributor
1
Reply
3
Views
5 Years
Discussion Span
Last Post by klemme
0

It works this way, but thanks anyways :-)

$(document).ready(function(){
  $(".nyheds_link").hover(function() {
  $(this).parent().animate({ backgroundColor: "#DDD" }, 800);},function() 
  {
      $(this).parent().animate({ backgroundColor: "#f5f5f5" }, 300);
  });
});
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.