JQuery checks the existence of elements (recommended) and jquery Elements
Javascript check element existence: even if this element is deleted, you are not worried about the javascript code error;
Jquery checks the element existence:
The Code is as follows:
If (! Document. getElementById ("preview") return false;
Jquery $ ("# preview") always gets an object even if this element is not present on the webpage.
You cannot use the following code:
If ($ ("# preview") {// do something}
Therefore, when jquery is used to check whether an element exists on a webpage, it should be determined based on the length of the obtained element.
The Code is as follows:
If ($ ("# preview"). length> 0) {// do something}
The above is the core code for jquery to check the existence of elements. I hope it will help you. If you have any questions, please leave a message. The editor will reply to you in time.