jquery - Chaining trigger after $(document).on() -


when binding event element old way, chaining trigger right after declaring binding easy:

$('#button').click(...).trigger('click'); 

but i'm binding events this:

$(document).on('click', '#button', function() { ... }); 

and attaching .trigger('click') not target specific element. there way solve 1 liner instead of having use:

$('#button').trigger('click'); 

on separate line right after?

you can find , trigger on document.

$(document).on('click', '#button', function() { ... })     .find('#button').trigger('click'); 

`$(document).on('click', '#button', function(){})' not needed in case because needed if elements dynamically added. if dynamically added, cannot trigger click.

so can first option question.

$('#button').click(...).trigger('click'); 

or can use

$('#button').on('click', function(){ } ).trigger('click'); 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -