The Onload Deception...Javascript JQuery function not defined? -


works:

<div onclick="updateattributes();">update</div>  <script> function updateattributes() {             alert(1);          } <script> 

doesnt work: (updateattributes not defined)

<div onclick="updateattributes();">update</div>  <script> $(function(){ function updateattributes() {             alert(1);          }  });  <script> 

why happening here? thought old onload safest bet declaration?

thanks!

in second example, updateattributes visible closure of ready callback function.

it works in first because function globally visible. second example, working, can modify to

$(function(){ $('div').click(updateattributes); function updateattributes() {             alert(1);         }  }); 

since updateattributes visible within callback itself. also, remove inline onclick handler in div itself.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -