How can I change the css display attribute of the ui-datepicker-calendar class after the datepicker has already been initialized? I have a html form with a selectable checkbox from which I want to toggle the display of this table. I’ve tried the following:
HTML sample:
<div class="row">
<div class="adddescr"><label for="date">Zeitraum:</label></div>
<div class="addinput" id="date"><input type="text" id="datefrom" name="datefrom" class="date" /> - <input type="text" id="dateto" name="dateto" class="date" /></div>
</div>
<div class="row">
<div class="addinput"><label><input type="checkbox" id="dateplanedcheck" /> grobe Planung</label></div>
</div>
JS first approach:
<script>
$(document).ready(function() {
$("#datefrom, #dateto").datepicker({ dateFormat: "dd.mm.yy",
[...]
beforeShow: function(input, inst) {
if ($("#dateplanedcheck").is(':checked')) {
$(".ui-datepicker-calendar").css("display", "none");
}}
});
[...]
});
<script>
The beforeShow is called, but the calender is still displayed.
JS second approach:
<script>
$(document).ready(function() {
[....]
$("#dateplanedcheck").change(function() {
if ($(this).is(':checked')) {
$(".ui-datepicker-calendar").css("display", "none");
}
});
});
</script>
What am I missing? Does this even work with jQuery?
Thanks in advance!
So you want to NOT show the calendar if the checkbox is checked?
Just
return false;in the beforeShow.http://jsfiddle.net/JzbPD/
Answer:
Still displaying the calendar but making it invisible:
BeforeShow can’t access the ui-datepicker-calendar on the table because it hasn’t been rendered yet. Apply a class like
$(inst.dpDiv).addClass('calendar-off')and then have the style.calendar-off table.ui-datepicker-calendar { display none; }like this: http://jsfiddle.net/JzbPD/4