Search code examples
javascriptjquerywindow-resizedocument-ready

Resize function doesn't work


When the page loads I need #book to take 80% width of the window, and the same need to happen when page is resized. I make the code bellow, but it doesn't work. Why?

<script type="text/javascript">
    $(document).ready(function(){
        $('#book').turn();
        $("#book").width = 80 + "%";
    });
    $(document).resize(function(){
        $('#book').css('width', '80%');
    });
</script>

Thanks!


Solution

  • $("#book").width = 80 + "%"; isn't correct JS/jQuery.

    You can change it to either

    $('#book').css('width', '80%'); 
    

    or

    $('#book').width('80%');
    

    Also, use $(window).resize() instead of $(document).resize()