开发者

Calling Function Itself in jquery

开发者 https://www.devze.com 2023-04-03 04:55 出处:网络
I have func开发者_Go百科tion like below $.fn.testFunction = function (options) { $(window).resize(function () {

I have func开发者_Go百科tion like below

$.fn.testFunction = function (options) {

    $(window).resize(function () {
       //call testfunction again
    });

    alert("Test");

}

If the window size changes, I want to call testFunction again. How can I do that ?

Thanks in advance,


Update: I just realized that you have options as well.

$.fn.testFunction = function _testFunction(options) {

    $(window).resize(function () {
       _testFunction(options);
    });

    alert("Test");
}


Your function gets stored in $.fn object, so you try calling it from there again:

$.fn.testFunction = function (options) {
    $(window).resize(function () {
       $.fn.testFunction();
    });

    alert("Test");
}
0

精彩评论

暂无评论...
验证码 换一张
取 消