I want it where the edit button appears and then when I clear the edit button, the 'edit' will change into 'save' and then the 'cancel' button will also be shown.
$('#edit').click(function() {
$(this).hide();
$('#save, #cancel').show();
});
$('#cancel').click(function() {
$('#edit').show();
$('#save, #cancel').hide();
});
.save,
.cancel {
display: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form>
<button type="button" class="btn btn-secondary" value="edit">Edit</button>
<button type="submit" class="btn btn-success" value="save">Save Changes</button>
<button type="button" class="btn btn-secondary" value="cancel">Cancel</button>
</form>
You did small mistakes in your code.
$('#edit').click(function() {
$(this).hide();
$('#save, #cancel').show();
});
$('#cancel').click(function() {
$('#edit').show();
$('#save, #cancel').hide();
});
$('#save').click(function() {
$(this).hide();
$('#cancel').hide();
$('#edit').show();
});
button.save, button.cancel {
display: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" />
<form>
<button type="button" class="btn btn-secondary" value="edit" id="edit">Edit</button>
<button type="submit" class="btn btn-success save" value="save" id="save" >Save Changes</button>
<button type="button" class="btn btn-secondary cancel" value="cancel" id="cancel" >Cancel</button>
</form>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With