Check if element Exists on the Page using jQuery

Today, We want to share with you Check if element Exists on the Page using jQuery.In this post we will show you Check For an Element on the Page with jQuery, hear for How to check if an element exists in jQuery we will give you demo and example for implement.In this post, we will learn about How to check a selector matches some content using jQuery? with an example.

Check if element Exists on the Page using jQuery

There are the Following The simple About jquery check if div exists by class Full Information With Example and source code.

  Laravel Eloquent Multiple WHERE clauses

As I will cover this Post with live Working example to develop jquery if element does not exist, so the jquery check if element exists in array is used for this example is following below.

jQuery length example

using jquery Example

if ($('#contact-form').length > 0) {
// do some source code that only applies to the contact form
}

index.html

simple you can use the .length property to check if an element exists.

<html>
<head>
<title>you can use the .length property to check if an element exists.</title>
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
</head>

<body>

<h1>jQuery check if an element exists</h1>

<script type="text/javascript">

  $(document).ready(function(){

    $("#contact1").click(function () {
		if($('#contact1').length){
			alert("contact1 exists");
		}else{
			alert("contact1 does not exists");
		}
    });

    $("#contact2").click(function () {
		if($('#contact2').length){
			alert("contact2 exists");
		}else{
			alert("contact2 does not exists");
		}	
    });
	
  });
</script>
</head><body>

<div id="contact1">
	<b>This is contact element which has an ide of "contact1"</b>
</div>

<hr/>
<hr/>
<hr/>

<input type='button' value='contact1 exists?' id='contact1'>
<input type='button' value='contact2 exists?' id='contact2'>

</body>
</html>

Web Programming Tutorials Example with Demo

Read :

  Laravel 6 Define Global Constants Config PHP file

Summary

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

I hope you get an idea about check if element exists javascript.
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.