简体   繁体   中英

Using `Not` with `Delegate` - Jquery

I currently have something like this:

$(".jtable tbody td").not(".DeleteLicense").hover(

How can I use delegate with this? Something like

$("#resultContainer,#approvalContainer,#createNewContainer").delegate(".jtable tbody td....

Thanks!

You can use the :not() selector to move the negation in to your selector.

$("#resultContainer,#approvalContainer,#createNewContainer")
    .delegate(".jtable tbody td:not(.DeleteLicense)", "...", ...);

Note that the jQuery documentation recommends using the .not() function rather than the :not() selector in most cases, but I'm not sure if it is possible in this case.

If you're willing to use another approach, you may find that you could use the .jtable tbody td selector in your call to delegate , and then use if(!$(this).is(".DeleteLicense")) { ... } in your event handler to only process elements that meet your criteria.

Like this:

$("#resultContainer,#approvalContainer,#createNewContainer").delegate(".jtable tbody td:not('.DeleteLicense')", "hover", function(eventObj) {
    // handler code
});

我的第一个想法是尝试使用:not()选择器

$("#resultContainer,#approvalContainer,#createNewContainer").delegate(".jtable tbody td:not('.DeleteLicense')", "hover", function(){ /* do stuff */});

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