I have an input element
<input type="submit" id="btn-submit-id"
class="btn btn-success btn-submit-employee employee-tag" value="Submit">
and is called using javascript onclick pointing to its class name btn-submit-employee -
$(".btn-submit-employee").on("click", function(e){ e.preventDefault(); alert('submit'); });
When the submit button is clicked, I change its value to value="Update" and at the same time, calling the addClass and removeClass function adding btn-update-employee as one of its class names and removing the btn-submit-employee class name. When I click the button the second time, it should call the function
$(".btn-update-employee").on("click", function(e){ e.preventDefault(); alert('Update'); });
but still it calls the javascript function pointing to class name btn-submit-employee even after I removed the class name btn-submit-employee using removeClass function. What is the problem with this? Below is my complete code. Thanks a lot.
Html element:
<input type="submit" id="btn-submit-id"
class="btn btn-success btn-submit-employee employee-tag" value="Submit">
Javascript:
$(".btn-submit-employee").on("click", function(e){
e.preventDefault();
$("#btn-submit-id").val("Update");
$(".btn-submit-employee").addClass("btn-update-employee");
$(".btn-submit-employee").removeClass("btn-submit-employee");
alert('submit');
});
$(".btn-update-employee").on("click", function(e){
e.preventDefault();
alert('Update');
});