To find out if an element exists in JavaScript, you can use various methods. One of the most common methods is to use the querySelector method if you want to select an element by its CSS selector.
index.tsx119 chars6 lines
Alternatively, you could use getElementById or getElementsByClassName methods depending on how you want to select the elements.
index.tsx278 chars12 lines
Note that the getElementsByClassName method returns an HTMLCollection, so you need to check its length property to know if any element with the specified class exists.
gistlibby LogSnag