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
Post a Comment