In this, JSfiddle has a checkbox, label, and submit button.
When the box is checked and click Submit, an x ββwill appear, as it is now.
If the box is unchecked and press the "x" button, it will disappear, as it is now.
The problem is that the "x" does not appear again if the checkbox is checked, and click the "Submit" button.
This is my code.
$('form').submit(function() { if( $("input[type=checkbox]").is(':checked')){ $("label").add(); }else{ $("label").detach(); } return false; }); <form action="" method="post"> <input id="element" signed" type="checkbox" checked> <label for="element">x</label> <button type="submit">Submit</button> </form>
Any idea what is wrong?
source share