Вопрос по if-statement, javascript, html – Проверьте, не существует ли div с javascript

89

Error: User Rate Limit Exceeded

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

}

Error: User Rate Limit Exceeded

Ваш Ответ

8   ответов
146
var myElem = document.getElementById('myElementId');
if (myElem === null) alert('does not exist!');
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
3

getElementByIdError: User Rate Limit ExceedednullError: User Rate Limit Exceeded

10

Error: User Rate Limit Exceeded

document.getElementById('some_nonexistent_id') === null

Error: User Rate Limit Exceeded

$('#some_nonexistent_id').length === 0
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded!document.getElementById('foo')?
Error: User Rate Limit Exceededdocument.getElementById()Error: User Rate Limit Exceeded
1

 var element = document.getElementById('myElem');
 if (typeof (element) != undefined && typeof (element) != null && typeof (element) != 'undefined') {
     console.log('element exists');
 }
 else{
     console.log('element NOT exists');
 }
1

Error: User Rate Limit ExceedednullError: User Rate Limit Exceeded

if (document.getElementById('elementId')) {
  console.log('exists')
}

Error: User Rate Limit ExceededexistsError: User Rate Limit Exceeded

71
if (!document.getElementById("given-id")) {
//It does not exist
}

Error: User Rate Limit Exceededdocument.getElementById("given-id")Error: User Rate Limit ExceedednullError: User Rate Limit Exceededgiven-idError: User Rate Limit ExceedednullError: User Rate Limit ExceededError: User Rate Limit Exceeded)

Error: User Rate Limit Exceeded
Error: User Rate Limit ExceedednullError: User Rate Limit ExceededfalseError: User Rate Limit ExceededToBoolean(null)Error: User Rate Limit Exceededfalse
Error: User Rate Limit Exceeded
8

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

if (!document.getElementById('MyElementId')){
    alert('Does not exist!');
}

Error: User Rate Limit Exceeded

if (!$("#MyElementId").length){
    alert('Does not exist!');
}
0

Error: User Rate Limit ExceededidError: User Rate Limit Exceeded

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

Похожие вопросы