Nov 19, 2014

Check if an Element Exists In DOM Using JQuery

Below jQuery code Will Check If The Element Is Presented In The DOM, You Can Call It On The Load Function Or Even A Click Function

$(document).ready(function(){
if ($("#someElement").length)

//The DOM element exists
}
else
{
//The DOM element doesn't exist
}
});

Copy Paste This Code Below And Simply Do What Ever Your Planning To Do With It

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Check if an Element Exists</title>
  
  </style>
  <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
  <script>
$( document ).ready(function() {
 if ($("#someElement").length)

//The DOM element exists
alert("someElement exist");
}
else
{
//The DOM element doesn't exist
alert("someElement doesn't exist");
}
});
  </script>
</head>
<body>

<div id="someElement" >someElement Div Comes Here</div>

</body>
</html>

No comments:

JWT Token Decode Using Jquery

When it come to authentication we use many mechanism. Ones the user authenticated we must keep these details somewhere safe. So we can share...