Sazaj Sazaj - 1 year ago 42
HTML Question

Checkbox is unchecked but the content of a checked checkbox is showing up

Just like the title says.
Here is my code:

$('#somediv').change(function() {
if(this.checked) {
else {

<input style="float: left;" type="checkbox" id="somediv" name="somediv">

This happens when the browser is refreshed. The content should not show up, because the checkbox is unchecked, but it is showing up.

Answer Source

if it's unchecked by default just set a display: none in css to the class and that'it

  display: none;

or, if it's a dynamic value check on document ready the value and set it, so when refreshing page it will show/hide according to the checkbox value

$(document).ready(function() {

$('#somediv').change(function() {

function check(checkbox){":checked") ? $('.leaflet-marker-pane').show() : $('.leaflet-marker-pane').hide();

check example here: FIDDLE