Add jQuery function to specific elements

前端 未结 9 1491
悲&欢浪女
悲&欢浪女 2020-12-07 18:56

I know that you can add new jQuery functions by $.fn.someFunction = function()

However, I want to add functions to specific elements only. I tried this

9条回答
  •  一向
    一向 (楼主)
    2020-12-07 19:11

    Yo, needed to do the same thing, came up with this. its nice cause you destroy the element and function goes poof! I think...

    var snippet=jQuery(".myElement");
    snippet.data('destructor', function(){
        //do something
    });
    snippet.data('destructor')();
    

提交回复
热议问题