javascript - jQuery replace old ID with new one -


i trying replace old id new 1 function not working. how can resolve error?

$("#addfield").click(function(){      alert($(this).data('id')+1);      $(this).data('id', + $('#addfield').data('id')+1);      console.log($(this).data('id'));  })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <a class="btn btn-success addfield" id="addfield" class="addfield" data-id="1">add field</a>

the problem increase value after setting newvalue.

in line: var newvalue = currentvalue++; happening 2 things:

1) var newvalue=currentvalue;

2) currentvalue=currentvalue+1

$(".addfield").click(function() {    $(this).attr('data-id', +$(this).attr('data-id')+1);  })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <a class="btn btn-success addfield" data-id="1" class="addfield">add field</a>


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -