Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call a function in jQuery on window resize?

Tags:

I've this code:

<script>             $(document).ready(function larg(){             var larghezza = $(document).width();             $("p.width").text("The width for the " + larghezza +                  " is px.");             });              $(window).resize(function() {             larg();              });             </script> 

I would like to call the function "larg" on window resize, but it doesn't work.. How to do that??

Thanks

like image 263
Luca Frank Guarini Avatar asked Apr 25 '12 09:04

Luca Frank Guarini


1 Answers

You can't declare functions that way, use it like this.

<script>  $(document).ready(larg);   $(window).resize(larg);   function larg(){   var larghezza = $(document).width();   $("p.width").text("The width for the " + larghezza + " is px.");  } </script> 

EDIT: changed code a bit, thanks commenters

like image 76
LHolleman Avatar answered Sep 22 '22 20:09

LHolleman