Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Java
  3. Question
Java

Check if a div exists with jquery

Asked by Lily Hemmings Jun 21, 2021 1.2K views 1 answer
Share

About this question

Yes, I know this has been asked a lot. But, it confuses me, since the results on google for this search show different methods (listed below)

$(document).ready(function() {jquery if div exists
    if ($('#DivID').length){
        alert('Found with Length');
    }
 if ($('#DivID').length > 0 ) {
        alert('Found with Length bigger then Zero');
    }
    if ($('#DivID') != null ) {
        alert('Found with Not Null');
    }
});

How to Check if a div exists with jquery?

EDIT: It's a pity to see that people do not want to learn what is a better approach from the three different methods. This question is not actually on "How to check if a div exists" but it's about which method is better, and, if someone could explain, why it is better?

Your answer

1 Answer

More Java discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Java Blogs

Guides, tips and career advice on Java from JanBask experts.