Answers for "javascript check is element exists"

8

js element exists

var element = document.getElementById("test");
    //If it isn't "undefined" and it isn't "null", then it exists.
if(typeof(element) != 'undefined' && element != null){
    alert('Element exists');
} else{
	alert('Element does not exist');
}
Posted by: Guest on February-02-2021
0

check if the element exists in javascript

<div id="test">Example DIV element.</div>
 
<script>
    //Attempt to get the element using document.getElementById
    var element = document.getElementById("test");
 
    //If it isn't "undefined" and it isn't "null", then it exists.
    if(typeof(element) != 'undefined' && element != null){
        alert('Element exists!');
    } else{
        alert('Element does not exist!');
    }
</script>
Posted by: Guest on June-02-2020

Code answers related to "javascript check is element exists"

Code answers related to "Javascript"

Browse Popular Code Answers by Language