简体   繁体   中英

Can I call my function in this example immediately instead of wrap it by anonymous function?

I don't know how to pass $(this) in direct call

var parentLI = $("#nav .parent");

parentLI.hoverIntent(function() {
    showUL($(this));
}, function() {
    hideUL($(this));
});

You can give the functions by reference:

parentLI.hoverIntent(showUL, hideUL);

Then in those functions you can refer to the element which raised the event by the this keyword:

function showUL() {
   var $el = $(this);
   // do something with $el...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM