Changing and using the id of a button

I have a simple form which i am clearing using a button with the id new but the button which i want to update the data also doubles up as a create new button.

This are the buttons http://jsfiddle.net/tde8Q/6/

This is the code

$("#new").click(function(){
$('#id').val("");
$('#firstname').val("");
$('#lastname').val("");
$('#city').val("");
$('#continent').val("");
$("#neworupdate").prop('value', 'Save New').attr('id', 'createnew');
});


$("#createnew").click(function(){
alert('this worked');
});

How would i use the createnew id?.

Upvotes: 0

Views: 37

Answers (1)

PSR
PSR

Reputation: 40318

You need to use .on()

$(document).on('click','#createnew',function(){
  alert('this worked');
});  

It is working for me now http://jsfiddle.net/tde8Q/7/

Upvotes: 1

Related Questions