I recently had a question about how to correctly check if an element exists with jQuery. I found the answer from here:
https://learn.jquery.com/using-jquery-core/faq
One guy I work with says the correct way to check should be:
if ($( "#myDiv" ) && $( "#myDiv" ).length ) { //do something }
This statement is false. The check of $( "#myDiv" ).length would simply return 0 if it's not found. To be sure, here's a code example with both an id found, and a second id that's not present:
console.log("Count of #myDiv's found: " + $("#myDiv").length);
console.log("Count of #AnotherMyDiv's found: " + $("#AnotherMyDiv").length);