How to execute Jquery code only once??

后端 未结 9 2092
梦谈多话
梦谈多话 2020-12-16 15:52

I have one jquery method and i used call that method on click of a button . So in that code i have one line \" $(\"#loadingMessage\").css(\'padding-top\',\'6%\');

9条回答
  •  我在风中等你
    2020-12-16 16:28

    If you have to run only once a generic function without a particular event binding then use this.

    $(document).one('ready', function(){
       // your code
       $("#id").on("click", function() {
            // other code
       });
    });
    

    Useful if inside a function that is called many times (prevents onclick event from beein fired many times)

提交回复
热议问题