Jeremy
Jeremy

Reputation: 35

JQuery apply bind to all children

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.

Upvotes: 1

Views: 3497

Answers (2)

Rob Beardow
Rob Beardow

Reputation: 871

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)

Upvotes: 0

James Skidmore
James Skidmore

Reputation: 50318

$("#eventsContent div").bind("mouseenter", function(){
  $(this).css("background","#F5F5F5");
});

Upvotes: 4

Related Questions