jQuery plugin bind to dynamically created element -
following sample plugin not work on dynamically created element.
see jsfiddle
$.fn.getdata = function() { homecoming this.click(function() { alert($(this).data("aloc")); }); }; $("a").getdata();
i can using jquery.livequery
plugin as
$("a").livequery(function() { $(this).getdata(); });
but want facility without livequery
in plugin
well delegated events need utilize .on()
per jquery 1.7 , after . here go have modified code below , working intend to.
jquery code:
//plugin $.fn.getdata = function () { homecoming $(document).on('click', 'a', function () { alert($(this).data("aloc")); }); };
live demo:
http://jsfiddle.net/dreamweiver/mskm6/9/
happy coding :)
jquery jquery-plugins
No comments:
Post a Comment