Firing an event using jQuery live or delegate

I would like to bind a handler to an element using jQuery live () or delegate (). Looking at the documents, I see that I can attach a handler for a custom event.

Is it possible for one of these jQuery functions to also trigger a handler? Basically I want to attach a handler function and run it once.

Thanks for any help.

+3
source share
2 answers

If you only want to call it once, then you might be better off with help . one () .

If you want to call an event that has already been bound, you can call the method . trigger () .

$('#foo').bind('click', function() {
      alert($(this).text());
    });
    $('#foo').trigger('click');
+2

ready, , .

0

Source: https://habr.com/ru/post/1737414/


All Articles