Jquery to determine whether a tag Id exists

Encountered in the project need to determine whether a div element has the id attribute

Use the property length 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 {}

With the discussion and solutions of netizens on Stack Overflow: https://stackoverflow.com/questions/17277821/jquery-if-element-has-an-id

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325669190&siteId=291194637