How To Check Whether Particular Div Is Present Using jQuery

Post Pic

There might be some scenarios where we need to check whether a particular DIV is visible or not and if that DIV is visible do some extra functionality. Below code might help us in understanding on how to code the same in jQuery if a specific scenario occurs.

I got into one similar scenario, Where I need to invoke a function when particular DIV is visible, if that particular DIV is not visible do not invoke any function. In-order to achieve this, in jQuery we do have one selector called Visible

Visible Selector: jQuery(‘:visible’)

Description: This selector selects all visible elements

Using this Visible selector we can achieve the output which we are looking for in this article.

Sample Example:

<script language="javascript">
                //call your function

Code Description: In the above example, If a particular div ID is visible – the IF condition which we are using will returns ‘true’.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript" src="" type="text/javascript"></script>
<div id="DivHide" style="display:none;">This div is not visible</div>
<div id="TheIDWhichWeAreLookingFor">If this Div is visible, invoke a function</div>
<script language="javascript">
                //call your function

Please let me know your feedback through the comment section provided below.

Related Entries...

You Might Like:


Please let us know your feedback about the article through the comments section below, we want to hear from you about our website. And your comment / advice may help us to serve you better in upcoming articles.

Thank You!
Vivekanand [Founder of DeveloperSnippets]

One Response

Very useful! I’m going to build a library of these snippets!!!!

Leave Your Response