A simple plugin
jQuery.fn.cleanHouse = function() {
//do stuff
}
$('.dirty').cleanHouse();
How can we make sure future elements $('.dirty') will automatically call cleanHouse() ?
I'm looking solution do something with the plugin itself
A simple plugin
jQuery.fn.cleanHouse = function() {
//do stuff
}
$('.dirty').cleanHouse();
How can we make sure future elements $('.dirty') will automatically call cleanHouse() ?
I'm looking solution do something with the plugin itself
It's not possible to achieve this. The only way the plugin can get called in the future is through an event.
is jquery's live() function what you need?
or this
The problem with .live() is that you can only use it in connection with an event, and there is no built-in event that fires when you add elements to the DOM.
But here's a detailed explanation on how you make that happen with a custom "create" event: http://www.erichynds.com/jquery/jquery-create-event/
I think what you are looking for is a combination, try something like this:
$.fn.cleanHouse = function() {
return $(this).live('click', function() {
//do stuff
});
}
$('.dirty').cleanHouse();