steven22
steven22

Reputation: 21

change global-variable inside jquery function

How do you change a global-variable inside a jquery function. If I use this code below it will display "0" and not "15".

<script type>
theValue=0;
      $(document).ready(function(){
    theValue=15;
     });
</script>

<script type="text/javascript">
    document.write(theValue)
</script>

Upvotes: 1

Views: 2774

Answers (1)

red-X
red-X

Reputation: 5128

Thats because when you write, the (document).ready hasn't fired yet. Example, notice it writes 0 but when you click the button its 15.

Upvotes: 2

Related Questions