I need help creating a toggle button. To see the code I'm working on, click here.
In my JavaScript code, I am reading the value of a 'checkbox'. If the value is true, I add another div with a close button. When the close button is clicked, I remove this newly added div from the DOM.
Everything is functioning correctly so far.
However, I also want to toggle back the button. I have tried setting the value to false using the line:
document.getElementsByName("addUserConfirmation").checked = false;
After doing this, the value is set to false but the toggle button remains blue. How can I turn it off?
Here is the snippet of code in question:
function removeCardRevertToggleButton(button, container) {
var parentContainer = document.getElementById(container);
jQuery(parentContainer).children().remove();
document.getElementsByName("addConfirmation").checked = false;
}
<div class="boxStyle">
<span class="closeButton" requestid="" onclick="removeCardRevertToggleButton(this, "inviteContainerContext")">×</span>
</div>
If you'd like to view the JSFiddle, you can find it here.
When the close ('x') button is clicked, I would like to switch the toggle button to the off position.