Checks if the specified target exists in the DOM.
target
Element, EventTarget, or CSS selector.
true if the specified target exists.
true
We allow null or undefined as well because a null or undefined element technically doesn't exist.
null
undefined
HTML
<ul> <li id="item-1">Item 1</li> <li id="item-2">Item 2</li></ul> Copy
<ul> <li id="item-1">Item 1</li> <li id="item-2">Item 2</li></ul>
Code
elementExists("#item-1");// trueelementExists(findElement("#item-1"));// trueelementExists("#item-3");// false Copy
elementExists("#item-1");// trueelementExists(findElement("#item-1"));// trueelementExists("#item-3");// false
Checks if the specified
target
exists in the DOM.