I need to check when an element is alive, I'm doing:
$('#obj').livequery(function() { ... });
How can I do it with live method or another way?
If it is your code that is adding the element to the DOM, then run your code on it when you create it:
$('body').append('<div id="obj">some new object</div>');
var obj = $('#obj');
obj.runSomeCode();
...or you can even do it before it is appended:
var obj = $('<div id="obj">some new object</div>');
obj.runSomeCode();
obj.appendTo('body');
This is an old question, but for the record, here my 5 cents:
An alternative to livequery
is to use a Publish/Subscribe
approach with for example this implementation
jQuery Tiny Pub/Sub: A really, really, REALLY tiny pub/sub implementation for jQuery.
I use it, for example, in this way:
// inform of DOM change (mostly through AJAX)
$.publish("/table/loaded");
// re-execute plugin
$.subscribe("/table/loaded", function(e, data) {
$("#my_id input[name='date']").datepicker();
});
+info : Understanding the Publish/Subscribe Pattern for Greater JavaScript Scalability
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