So basically, when I hit save, the var name should become the new text I entered in the input box, not the original name.
However, right now, no matter what I enter, it reverts it back to the original value.
$(document).ready(function() {
$('.edit-name').on('click', function() {
$(this).closest('div').find('span,input').toggle();
});
var name = $('#name').val();
$('#submit').on('click', function() {
$('#result').html(name);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="submit">Save</button>
<div id="result"></div>
<div class="editable">
<span>John</span>
<input type="text" id="name" name="name" value="John" style="display:none;" />
<i class="edit-name">Edit</i>
</div>