Why does the alert not work after adding the DOM? Should show "blah blah" after clicking on it.
<!doctype html> <html> <head> <title>test</title> <meta charset="UTF-8"> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script> $(document).ready(function() { $('#main_body').append("<h1>Hello</h1><input id=\"but\" type=\"button\">Click"); $( "#but" ).on( "click", function() { alert( "bla bla" ); }); }); </script> </head> <body id="main_body"> </body> </html>
SOLVE
The main problem was with this:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
JQuery was too old i think
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
resolved problem :)
javascript jquery
user3345547 Mar 13 '14 at 9:01 2014-03-13 09:01
source share