Answers for "if element exist"

22

jquery check if element exists

// Check if an element currently exists
if ($('#element').length) {

}
Posted by: Guest on June-05-2020
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
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
-2

jquery check if element still exists

$(function() {
    var $button = $(".the_button");
    alert (isStale($button));
    $button.remove();
    alert (isStale($button));
});
    
function isStale($elem)
{
    return $elem.closest("body").length > 0;
};
Posted by: Guest on April-17-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language