$('#id').bind('change',function() {
//do something
}).trigger('change');
it works fine. but if id2 has been generated by using AJAX
i am trying to use
$('#id2').live('change',function() {
//do something
}).trigger('change');
But its not working. Can anybody help me please. Thanks
If you write
$('#id2').live('change',function() {
//do something
});
then you do this because #id2
is not created yet. trigger('change')
on the other hand immediately triggers an event. But if the element does not exist yet, calling it has no effect.
You need to call trigger()
once the element is created:
$('#id2').trigger('change');
There is no need to use live()
if #id2
already exists. You can just use bind()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With