Check if element is in DOM or not with jQuery?

I have a quick and easy question. How can I check if an element is in the DOM or not?

For example, how can I check if <p id="does_i_really_exist_or">this is just matrix</p>

+4
source share
3 answers
 if ( $("#does_i_really_exist_or").length ) { //-- It does exist. } 
+9
source
 if ($("#does_i_really_exist_or").length > 0) { // do something } 
+5
source

there are three different ways:

 if ($("#does_i_really_exist_or").length > 0) { // do something } if ($("#does_i_really_exist_or").size() > 0) { // do something } if ($("#does_i_really_exist_or")[0]) { // do something } 
+3
source

All Articles