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
Post a Comment