I need to send this
to the capIn() and capOut() functions so that I can target the children divs of the correct .slide. How do I pass this
to a function. this
would be what is hovered.
$(".slide").hover(function(){capIn();capOut();});
Looking at the function names capIn
and capOut
it makes sense that they are 2 different behaviors. I believe you have 2 different behaviors on mouseenter
and mouseleave
events. hover
method can take 2 methods, one for mouseenter
and another for mouseleave
. You can try this
$(".slide").hover(capIn, capOut);
You can use this
inside capIn
and capOut
it will point to .slide
element which you hovered on.
function capIn(){
var $childrens = $(this).children();
}
function capOut(){
var $childrens = $(this).children();
}
$(".slide").hover(function(){
capIn.apply(this);
capOut.apply(this);
});
See here: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/apply
UPDATE:
If capIn
is for mouseenter
and capOut
is for mouseleave
, then:
$(".slide").hover(function(){
capIn.apply(this);
}, function(){
capOut.apply(this);
});
ShankarSangoli
's solution is more succinct, but if any arguments need to be passed in addition to this
, then: capIn.apply(this, arguments)
can be used.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With