I have code that should change the anochor and the id value when clicking on it. The value and the anchor are changing, but only 1 time. can you tell me why it's not working?
HTML
<a href="#" id="enable-edit-button">EDit</a>
JS
<script type="text/javascript">
$(document).ready(function()
{
$("#enable-edit-button").click(function()
{
$(this).attr("id","save-edit-button");
$(this).html("SAVE");
});
$("#save-edit-button").click(function()
{
$(this).attr("id","enable-edit-button");
$(this).html("EDIT");
});
});
</script>
答案 0 :(得分:0)
你的问题在这里定义.. Difference between .on('click') vs .click()
$('body').on('click', '#save-edit-button', function() { ... });
答案 1 :(得分:0)
试试这个
$(document).ready(function ()
{
$(document).on('click', "#enable-edit-button", function ()
{
$(this).attr("id", "save-edit-button");
$(this).html("SAVE");
});
$(document).on('click', "#save-edit-button", function ()
{
$(this).attr("id", "enable-edit-button");
$(this).html("EDIT");
});
});