Question

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!

Was it helpful?

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()

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top