If I have a jQuery plugin as follows:
(function($)
{
$.fn.somefunction = function(text, options){
...function code goes here
};
$('.selector_name').somefunction();
})(jQuery);
How do I cause it to be bound with the .on function so that it will run for dynamically loaded elements.
I have tried:
(function($)
{
$.fn.somefunction = function(text, options){
...function code goes here
};
$('.selector_name').on.somefunction();
})(jQuery);
but that gives me a JScript runtime error: “Object doesn’t support property or method ‘somefunction’.
How should I be doing this?
If you want to bind your function to dynamically loaded elements then do it when they are added.
onbinds to events, not to functions.There is no ‘on element created’ method in jQuery. When you are adding them you will need to do the work of binding to them if need be.