Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery difference between bind('resize') vs .resize()

Tags:

jquery

  1. What is the difference between $(window).bind('resize') and $(window).resize()?
  2. I saw somewhere bind nested over resize. What impact does it have? See code below.
  3. I know .resize() works on elements as well as window. Does bind work in similar way too... like $('#el').bind('resize', function (event) { // stuff });?

JS:

$(window).bind('resize', function (event) {
    $(window).resize(function () {
         // do something here
    });
});
like image 332
django Avatar asked Oct 20 '22 22:10

django


1 Answers

From jQuery page .resize():

This method is a shortcut for .on('resize', handler).

and .on() is:

The .on() method attaches event handlers to the currently selected set of elements in the jQuery object. As of jQuery 1.7, the .on() method provides all functionality required for attaching event handlers. For help in converting from older jQuery event methods, see .bind(), .delegate(), and .live().

So based on jQuery api description, I think there is no difference it's just a shortcut similar to $.click() and others

like image 64
Alex Art. Avatar answered Nov 02 '22 08:11

Alex Art.