Home » Check if element Exists on the Page using jQuery

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.

Read Also:  Laravel Clear Cache Using Artisan Command (CLI)

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.

Read Also:  jQuery Check if element exists or not

<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 :

Read Also:  Vuejs check if Element Exists Example

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.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Top 10 Greatest US Latest Technology Products
  2. Read Also:  Laravel MySQL Advanced Query Techniques with Example
  3. Read Also:  Laravel 6 Guzzle HTTP Client Request Example
  4. Read Also:  jQuery AJAX Inline CRUD using Laravel MySQL
  5. Read Also:  sticky Scroll Back to Top Button using jQuery and CSS
  6. Read Also:  Server side Laravel DataTables example
  7. Read Also:  jQuery check if an element is exists in dom
  8. Read Also:  How to Check If an Element Exists in jQuery?
  9. Read Also:  Vuejs Editable Grid component - GridView in Vue.JS
  10. Read Also:  Laravel Google Maps Geocoding Example

Leave a Comment

Your email address will not be published. Required fields are marked *