Tuesday 10 November 2020

positional method instead of selector in jquery event

I'm catching a custom event like this:

$("#my_div").on("custom_event", ".some_class:first", function...

That is working fine. The thing is that because jQuery 3.4 is deprecating :first selector (among others), I would like to do something like

$("#my_div").on("custom_event", $(".some_class").first(), function...

But that doesn't work because the selector parameter must be a string. In my case the event is captured on second, third, etc. besides the first one. I need to only be captured on first.

How can I update the code? I would like to avoid and if statement to test the position, is there a way to make it work like before?



from positional method instead of selector in jquery event

No comments:

Post a Comment