Gelin Luo
Gelin Luo

Reputation: 14373

jquery resize() not work?

This might be very stupid, but I am not sure where I am wrong. I found jQuery 'resize()' not work at all. Check this fiddle: http://jsfiddle.net/FefFW/1/

<div id="log"></div>

jQuery:

$(function(){
    $('#log').append('<h3>event log</h3><hr/>');
    $('window').resize(function(){
        $('#log').append('<p>resizing...</p>');
    });  
});

Upvotes: 3

Views: 1103

Answers (3)

adeneo
adeneo

Reputation: 318162

$(function(){
    $('#log').append('<h3>event log</h3><hr/>');
    $(window).on('resize', function(){
        $('#log').append('<p>resizing...</p>');
    });
})​;

FIDDLE

Upvotes: 4

NewInTheBusiness
NewInTheBusiness

Reputation: 1475

Have you remembered to put it within $(document).ready(function() { }); ?

And yeah, like the rest just noted when watching the fiddle 'window' is wrong.

Upvotes: -1

SLaks
SLaks

Reputation: 887205

"window" is not a selector; there is no <window> element.

You want $(window).

Upvotes: 6

Related Questions