Sebastian Jeliazkov Sebastian Jeliazkov - 5 months ago 24
Javascript Question

Jquery nth-child loop

I got "N" div containers all with same class "test" and inside i got divs.

How can i change background on hover on only one of the container's divs(all of them).I tryed with

('div').parent('test')
but its hovering all of the containers.

My code i already tried but its not working:

$(document).ready(function() {
$('.test').each(function() {
$('.test').hover(function() {
$('div').parent('.test').css('background','#000000');
},function() {
$('div').parent('.test').css('background','#FFFFFF');
});
});
});


The HTML PART:

<div class="test" data-href="index.php?page=customerinfo&nodeid='.$usernode['id'].'">
<div class="col-md-3">

'.$usernode['name'].'
</div>
<div class="col-md-1">
('.str_pad($usernode['id'],4,'0',STR_PAD_LEFT).')
</div>
<div class="col-md-2">
'.long2ip($usernode['ipaddr']).'
</div>
<div class="col-md-2">
'.$mac.'
</div>
<div class="col-md-1">
&nbsp;
</div>
<div class="col-md-1">
LAN1
</div>
<div class="col-md-2">
<img src="img/access.gif" />
<img src="img/warningoff.gif" />
<img src="img/delete.gif" />
<img src="img/edit.gif" />
<img src="img/info.gif" />
</div></div>


there is N containers with class="test" so i dont know how to do it properly

Answer

Whenever your mouseenter class test it changes it's background.

$(document).ready(function(){
    $(".test").on("mouseenter",function(){
    $(this).children('div').css('background','red');
  });
  $(".test").on("mouseleave",function(){
    $(this).children('div').css('background,'none');
  });
});
Comments