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();});
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();});
Share
Improve this question
asked Feb 10, 2012 at 15:21
Jonathan EckmanJonathan Eckman
2,0774 gold badges25 silver badges51 bronze badges
1
|
3 Answers
Reset to default 11Looking 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.
This works for me:
function capOut(jq) {
alert(jq.hasClass('slide'))
}
$(".slide").hover(function () {
capIn(this),
capOut($(this)) //to pass a jQuery object wrapping 'this'
});
mouseenter
andmouseleave
events? – user1106925 Commented Feb 10, 2012 at 15:25