Answers for "javascript check if id exists in dom"

1

check if an id exists javascript

var myEle = document.getElementById("myElement");
    if(myEle){
        var myEleValue= myEle.value;
    }

//the return of getElementById is null if an element is not actually 
//present inside the dom, so your if statement will fail, because null 
//is considered a false value
Posted by: Guest on July-07-2021
3

js check if dom element exists

var myElement = document.getElementById("myElementID");

if(!myElement){
    //#myElementID element DOES NOT exist
}

if(myElement){
    //#myElementID element DOES exists
}
Posted by: Guest on August-05-2019

Code answers related to "javascript check if id exists in dom"

Code answers related to "Javascript"

Browse Popular Code Answers by Language