I want to update an input of one field to be data attribute of another field. I manage to do it once, but doesn't work the second time.
$('button').click(function() {
$('[data-key="hello"]').attr('data-key', $('[data-id="hi"]').val())
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input data-id="hi">
<input data-key="hello">
<button>Click</button>
How do I make it update every time I click the button? Why doesn't it work every time?