How to check if an element or HTML tag exists using JavaScript?

<!DOCTYPE html>
<html>
<body>
<div id="find-me"></div>
<script>
var elementExists = document.getElementById("find-me");
if (typeof(elementExists) != 'undefined' && elementExists != null)
{
  alert("find-me id exist");
}

var h5 = document.querySelector('h5');
if (typeof(h5) != 'undefined' && elementExists != null)
{
  alert("h5 not exist");
}
</script>

</body>
</html>
Most Helpful This Week