Ben Marshall
Ben Marshall

Reputation: 1764

jQuery $(window).resize not firing within jQuery plugin

I've created a custom jQuery plugin and having issues getting the window resize function to fire within the plugin. Broke it down to the basics of what I got, can't figure out why it's not firing:

;(function ( $, window, document, undefined ) {
  $.fn.test = function(options) {
    $(window).resize(function() {
      alert('sdsd');
    });
  };
})(jQuery);

$(function() {
  $('.element').test();
});

Upvotes: 0

Views: 1393

Answers (1)

Kevin B
Kevin B

Reputation: 95066

In your case window is undefined because you aren't passing it into the function.

;(function ( $, window, document, undefined ) {
  $.fn.test = function(options) {
    $(window).resize(function() {
      alert('sdsd');
    });
  };
})(jQuery, window, document); //<--- changes here

Upvotes: 4

Related Questions