Sunday, 15 June 2014

jquery - Javascript generic function add loader to button -



jquery - Javascript generic function add loader to button -

i need create generic function can apply buttons adds loader image button adding class button when clicked , hides image 1 time whatever function button triggered has returned.

how using jquery?

this code i've got far.

var b ={ addspinner: function () { $(this).click(function(){ $(this).addclass('.spinner'); }); } };

am using this correctly select clicked button? practice have function remove class 1 time function button triggered returned, or improve have in addspinner function? how hear event?

thanks

try making plugin

(function ( $ ) { $.fn.classtoggler = function(cssclass) { $(this).click(function(){ $(this).toggleclass(cssclass); }); homecoming this; }; }( jquery ));

now utilize it

$("#mybutton").classtoggler("spinner").click(function(){ //do other stuff });

demo: http://jsbin.com/makoxibogeje/1/edit

jquery button

No comments:

Post a Comment