The point of this code is to toggle back and forth between two versions of innerHTML within the div, using the input values (or the default values) and also toggle how the button displays. It is not working. After the first click, the "new" button fails. The div is supposed to revert back to the original display with the blank input fields.
I've looked at a few other questions on the .toggle method, but it's deprecated, and it's unclear what the best fix is. There doesn't seem to be much consensus on an approach. Here are the other threads I found for reference:
- JQuery Button Click Not Working
- Toggling Click Handlers in Javascript
- Toggle Between Two Different Click Events
Here is a jsfiddle example of what I am trying to do.
HTML Code:
<div id="case-name">Case Name: In the Matter of <input id="input-petitioner" type="text" placeholder="Petitioner" maxlength="50"></input> and <input id="input-respondent" type="text" placeholder="Respondent" maxlength="50"> <button id="case-name-submit" type="button" value="none">Submit</button></div>
Script:
$(document).ready(function(){
//EVENT TRIGGERS AND ACTIONS
$('#case-name-submit').on('click', function(){
$('#case-name').fadeOut('fast').html(
'Case Name: In the Matter of ' + $('#input-petitioner').val() + ' and ' + $('#input-respondent').val() + ' <button id="case-name-change" type="button" value="none">Change</button>'
).fadeIn('fast');
});
$('#case-name-change').on('click', function(){
$('#case-name').fadeOut('fast').html(
'Case Name: In the Matter of <input id="input-petitioner" type="text" placeholder="Petitioner" maxlength="50"></input> and <input id="input-respondent" type="text" placeholder="Respondent" maxlength="50"> <button id="case-name-submit" type="button" value="none">Submit</button>'
).fadeIn('fast');
});
});