Skip to content
Advertisement

Receive logical value if a variable exist

I would like to check if a variable exist in the dom and receive a true false answer.

I try this command:

document.body.contains(document.querySelectorAll('div.grid'))

but it is not working

any idea how can I change to have the right option?

Advertisement

Answer

const containsElement = document.querySelectorAll('div.grid').length !== 0
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement