

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to check if element exists in the visible DOM?
We can use the Node.contains method to do this check. The Node.contains() method returns a Boolean value indicating whether a node is a descendant of a given node, i.e. the node itself, one of its direct children (childNodes), one of the children's direct children, and so on.
Example
For example, you are looking for an element with id test, you can use the following −
const elem = document.querySelector('#test'); console.log(document.body.contains(elem));
This will log true or false based on whether the element is present in the visible DOM.
- Related Questions & Answers
- How to check if an element is visible with WebDriver?
- How to check if event exists on element in jQuery?
- How to check if onClick exists on element in jQuery?
- How to check if Element exists in c# Selenium drivers?
- Check if a particular element exists in Java LinkedHashSet
- Check if element exists in list of lists in Python
- Java Program to check if a particular element exists in HashSet
- Check if table exists in MySQL and display the warning if it exists?
- How to find if element exists in document - MongoDB?
- How to check if a MySQL database exists?
- How to check if a div is visible using jQuery?
- Check if MongoDB database exists?
- How to check if a variable exists in JavaScript?
- How to check if a column exists in Pandas?
- How to check if a file exists in Golang?
Advertisements