Explore Topics

Check if an Element Is Hidden or Visible Using JavaScript

Last Updated : 18 Apr, 2025 - Asked By Ashok

js  find hidden element 

Answers
2023-11-28 12:13:03

To check if an element is hidden or not using JavaScript, you can use the window.getComputedStyle() method. This method returns an object containing the values of all CSS properties of an element. You can then check the display or visibility property of the element to determine if it is hidden or not. Eg:

const element = document.getElementById('myElement');
const style = window.getComputedStyle(element);
const display = style.getPropertyValue('display');
const visibility = style.getPropertyValue('visibility');

if (display === 'none' || visibility === 'hidden') {
  console.log('The element is hidden.');
} else {
  console.log('The element is visible.');
}

 

Alternatively, you can use the jQuery :hidden selector to check if an element is hidden . Eg:

if ($('#myElement').is(':hidden')) {
  console.log('The element is hidden.');
} else {
  console.log('The element is visible.');
}

 

Your Answer



Other Resources

Quiz Image
Quiz

Test your knowledge with interactive quizzes.

Interview Questions Image
Interview Questions

Prepare for interviews with curated question sets.

Q&A Image
Q&A

Ask your coding-related doubts and get answers.

Certification Image
Certification

Earn certifications to enhance your resume.

internships Image
Internships

Hands-on projects to improve your skills.

Quiz Image
Quiz

Test your knowledge with interactive quizzes.

Interview Questions Image
Interview Questions

Prepare for interviews with curated question sets.

blog Image
Blogs

Add your technical blogs and read technical topics.

Certification Image
Certification

Earn certifications to enhance your resume.

Q&A Image
Q&A

Hands-on projects to improve your skills.

People Also Asked