Home  >  Article  >  Web Front-end  >  How does Jquery determine whether a certain tag ID exists?

How does Jquery determine whether a certain tag ID exists?

coldplay.xixi
coldplay.xixiOriginal
2020-11-26 14:01:143582browse

How jquery determines whether a certain tag ID exists: Use the length attribute of the jQuery object to determine. If [>0] exists, the code is [if($("#id")[0] ){} else {}].

How does Jquery determine whether a certain tag ID exists?

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 a certain tag ID exists:

In the project, I encountered the need to determine whether a certain div element has the id attribute

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

or

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

or native js

if(document.getElementByIdx_x_xx_x("id")){} else {}

Related free learning recommendations: javascript (video)

The above is the detailed content of How does Jquery determine whether a certain tag ID exists?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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