Im tying to add a button when its clicked, and the new button to alert something when that is clicked, but at the moment its not alerting the message for when the new button is clicked
So what am i doing wrong with this.
here is what i have so far
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#first').bind('click', addbtn);
$('#second').on('click', alert);
function addbtn(){
$('.box').html('<input type="submit" value="Click me" id="second" />');
}
function alert(){
alert("works");
}
});
</script>
</head>
<body>
<input type="submit" value="Click me" id="first" />
<div class="box"></div>
</body>
</html>
$('.box').on('click','#second', alert);or bind the event after adding the element.$(parent).on(event, element, callback);