javascript alert firing on document ready even though it's in click event -


i've got simple question, code below keeps firing alert when page loads, alert in click event don't know why. ideas?

<script> $(document).ready(     function () {         var blah = document.getelementbyid('btnchangescreensize');         var blah2 = $('#btnchangescreensize');          $('#btnchangescreensize').click(alert(1));     } ); </script> 

thanks,

write this:

$(document).ready(     function () {         var blah = document.getelementbyid('btnchangescreensize');         var blah2 = $('#btnchangescreensize');          $('#btnchangescreensize').click(function() { alert(1) });     } ); 

the thing is, when write: $('#btnchangescreensize').click(alert(1)) function alert() being called , returns undefined. you're setting undefined callback function, doesn't make sense


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -