Check if Element Exists - Jquery

How to check whether an element exists or not using jquery?

Snippet Code


  
Rate this page :
  [ 0 votes]

Here the code is used to find the element is exiting or not. For example, inside the div element an id "mydiv" is given. Using the length of the div, existence of element is identified.

<script type='text/javascript'> $(document).ready(function(){ $("#ele_chk").click(function(){ if ($("#mydiv").length>0) { alert("Element is exist"); } else { alert("Element is not exist"); } }); }); </script> <div id='mydiv'>test</div> <input type='button' value='Check it' id='ele_chk'>

Tags


Ask Questions

Ask Question