How to call a function in jQuery on window resize?

function, jquery

Solution

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

Problem

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

Original source