Home > Web Front-end > JS Tutorial > body text

How jquery determines whether there is a problem with an object

coldplay.xixi
Release: 2020-12-22 15:38:06
Original
1598 people have browsed it

Jquery method to determine whether an object exists: 1. Use the length attribute of the jQuery object to determine if [>0] exists, the code is [ if($("#id")[0]) {} else {}]; 2. Use native Javascript code to judge.

How jquery determines whether there is a problem with an object

The operating environment of this tutorial: Windows 7 system, jquery version 3.2.1. This method is suitable for all brands of computers.

Jquery method to determine whether an object exists:

Correct use to determine whether an object exists:

if($("#id").length>0){}else{}
Copy after login

Use the length attribute of the jQuery object to determine , exists if >0.

or

 if($("#id")[0]){} else {}
Copy after login

Or directly use the native Javascript code to judge:

 if(document.getElementByIdx_x("id")){} else {}
Copy after login

Related free learning recommendations: javascript (video)

The above is the detailed content of How jquery determines whether there is a problem with an object. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template