Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>jQuery Test Element Exists or Not</title> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ if($("#myDiv").length){ alert("The element you're testing is present."); } }); }); </script> </head> <body> <div id="myDiv"></div> <p>The quick brown fox jumps over the lazy dog</p> <button>Check Element</button> </body> </html>