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
Post a Comment