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