How to Check If an Element Exists in jQuery?

Question: How do you check if an element exists or not in jQuery? In jQuery Example, We can use the simple . length property (Count a total number of the matched HTML DOM elements) to check if an element exists or not?.

You can use the Simple CDN Of the jQuery .length property to check whether HTML an element exists or not in phase if you want to trigger some jquery event only if a specific Data element verify exist in HTML DOM. also You can learn All about HTML Dom Check some property

jquery check if element exists,jquery check if element exists in dom,jquery check if element exists in array,jquery if element does not exist,jquery check if dynamic element exists,jquery check if element exists stackoverflow,check if element exists javascript,jquery check if div exists by class,jquery if element exists by id,jquery check if element exists
jquery check if element exist

let’s start to learn an example below that shown an alert on button trigger if the each data element exist or not.

You need to included # before HTML element id or also you can alternative way to use check if div exist by class, ID, Tag, jquery if element exist or not Like as a below Example

$('#player_info').length

Example : Check if element exist in jQuery

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>www.pakainfo.com - jQuery Test Element Exist or Not</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        if($("#player_info").length){
            alert("The virat kohali Team India is present.");
        }
    });
});
</script>
</head>
<body>
    <div id="player_info"></div>    
    <p>Virat Kohli is great an international player who currently Cool captains the India national Cricket team.</p>
    <button>get Information</button>
</body>
</html>

Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about jquery check if element exist.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.


Related FAQ

Here are some more FAQ related to this Article:

  1.   JQuery Push Key And Value Into An Array
  2.   Javascript Autocomplete Address Using PHP With Demo
  3.   Check if element Exists on the Page using jQuery
  4.   jQuery check if an element is exists in dom
  5.   jQuery Ajax Calling Laravel Example From Scratch
  6.   javascript Converting Strings to Number Example
  7.   Get Radio Button value using jQuery Example
  8.   jQuery Check if element exists or not
  9.   jQuery Check if Element Exists Example
  10.   Convert JavaScript Array to JSON Example