I have seen two ways to check if an element with a specific ID exists on the page and I was wondering why the second way works.
One way I have seen is the following and I think I understand it:
if ( $('#elementID').length > 0 ) {
//Do something
}
else {
//Do something else
}
Another way I have seen this done that I do not quite understand is the following:
if ( $('#elementID')[0] ) {
//Do something
}
else {
//Do something else
}
What does the [0] mean? I normally see [...] used for array's so is this returning an array?
Thank you.