Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically check to see if calendar has been rendered

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

I want to do a simple conditional statement to see if the calendar has already been rendered within a div. Something like this:

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

I want to do this so that I can remove, then re-init the calendar programatically. Basically, a 'reset' button.

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

Thank you in advance!!

like image 920
MVO Avatar asked Jul 14 '10 18:07

MVO


1 Answers

I figured it out. jQuery has a .children() selector. I was able to do a conditional statement on the .length property of that selector to see if there was any content in the div:

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

An alternative way to do this, without jQuery, is:

getElementById('calendar').hasChildNodes()
like image 114
MVO Avatar answered Oct 14 '22 06:10

MVO