Programmatically check if the calendar has been completed

It should be simple, but I'm stupid, so ...

I want to make a simple conditional statement to see if a calendar has already been displayed in a div. Something like that:

if ( $('#calendar').fullCalendar() ) { alert("calendar exists!!"); } 

I want to do this to delete and then restart the calendar programmatically. Basically, the reset button.

Can someone please let me know the correct syntax to check if a fullCalendar object has been provided?

Thanks in advance!

+7
javascript jquery fullcalendar
source share
3 answers

I get it. jQuery has a .children() selector. I was able to make a conditional statement in the .length property of this selector to find out if there is any content in the div:

 if ( $('#calendar').children().length > 0 ) { alert("calendar exists!!"); } 

Alternative way to do this without jQuery:

 getElementById('calendar').hasChildNodes() 
+6
source share

This is a kind of hack, but every day the cell has a class with the format fc-day-## . The last cell is numbered 41 (check this in firebug). You can try choosing td.fc-da-41 , and if you get any items, then the calendar will be fully loaded.

 if ($('td.fc-day-41').size() > 0) { //calendar ready } 

Maybe set it to check every few hundred milliseconds with .setTimeout()

 var checkCal = function() { if ($('td.fc-day-41').size() > 0) { //calendar ready } else { window.setTimeout(checkCal(), 200); } } 
0
source share

You can easily check something like

 if($('#calendar>*').length !== 0) alert("calendar exists!!"); 
0
source share

All Articles