Check if a div does NOT exist with javascript

前端 未结 9 2209
野性不改
野性不改 2020-12-12 16:42

Checking if a div exists is fairly simple

if(document.getif(document.getElementById(\'if\')){

}

But how can I check if a div with the give

9条回答
  •  难免孤独
    2020-12-12 17:24

    I do below and check if id exist and execute function if exist.

    var divIDVar = $('#divID').length;
    if (divIDVar === 0){ 
        console.log('No DIV Exist'); 
    } else{  
        FNCsomefunction(); 
    }   
    

提交回复
热议问题