extend - jQuery rebind off on when loaded via ajax -


i want provide extension jquery re-bind event handlers. because event handlers bound when partial view loaded using ajax , bound $(document) fire on page.

however if page not refreshed when partial downloaded once more 2 events bound. , on.

hence created extension unbind previous event , re-add it.

is plausible solution?

jquery.fn.extend({      offon: function (types, selector, data, fn) {         this.off(types, selector, fn);         this.on(types, selector, data, fn);     }  }); 

used within partial loaded via click event on main page.

<script type="text/javascript">   $(function() {     $(document).offon('click', '#my-details-section  a.delete-row', ondeleterow);      function ondeleterow() { // } });  </script> 

i recommend taking @ creating plugin. it's quite easy. here's documentation started: creating jquery plugin

this allow reuse more ease.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -