jQuery code to check if an object exists:
***********************mistake***********************
if($("#id")){}else{} because $("#id") returns object regardless of whether the object exists.
***********************correct***********************
if($("#id").length>0){}else{} uses the property length of the jQuery object to determine if > 0 exists.
or
if($("#id")[0]){} else {}
or
Use native Javascript code to judge directly: if(document.getElementById("id")){} else {}