How to check if element is exists or not in jQuery?
This tutorial is on How to check if the element exists or not in jQuery. You can use jquery most of the time we require to check element exists or not. we use the jquery provide length() method that can help to check element exists or not.
Example
<!DOCTYPE html> <html lang="en"> <head> <title>How to check if element is exists or not in jQuery?</title> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> </head> <body> <h2>How to check if element is exists or not in jQuery?</h2> <div id="div_element"></div> <button class="btn">Check Element</button> <script> $(document).ready(function(){ $(".btn").click(function(){ if($("#div_element").length){ alert("The div element is present."); } else { alert("The div element is not present."); } }); }); </script> </body> </html>