views:

501

answers:

2

I have:

$(document).ready(function(){
 $("#eventsContent").children().each(function(){
   $(this).bind("mouseenter", function(){
    $(this).css("background","#F5F5F5");
  });
 });
});

I have tried this a couple different ways, but this is the jist of what i've done.

I have a container div with numerous divs within it. I want to bind a MouseEnter event to each inner div respectively (and eventually a mouseout, once i see what's done it will be easy to expand upon).

Thanks for you help in advance.

+2  A: 
$("#eventsContent div").bind("mouseenter", function(){
  $(this).css("background","#F5F5F5");
});
James Skidmore
This wont work for ALL the divs separately will it?say you mouse over div1, i'd like only div 1 to change.
Jeremy
Yes, it will work for all of the DIVs independently. When the mouse enters one of the DIVs, the background of that DIV only will change.
James Skidmore
worked like a charm, thanks :)
Jeremy
No problem! Happy to help.
James Skidmore
It works because "this" refers to the element on which the event occurs.
Patrick McElhaney
A: 

Try a hover:

$(document).ready(function () {
    $("#eventsContent").children().each(function () {
        $(this).hover(
             function () { $(this).css("background", "#F5F5F5") },
             function () { $(this).css("background", "#000000") }
        );
    });
});

(Didn't test code)

Rob Beardow
Same concept as what i have written, i believe my problem lies in the selector.
Jeremy