Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/429.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 检查jquery对象的id是否为空_Javascript_Jquery - Fatal编程技术网

Javascript 检查jquery对象的id是否为空

Javascript 检查jquery对象的id是否为空,javascript,jquery,Javascript,Jquery,我试图检查jquery对象是否为null,以便以这种方式使用它 var reminder_history_div = $(".history-container"); if(reminder_history_div) reminder_history_div.scrollTop(reminder_history_div[0].scrollHeight); 但是提醒\u history\u div不是null或为空,其对象和一些信息,检查是否为空的正确方法

我试图检查jquery对象是否为null,以便以这种方式使用它

var reminder_history_div = $(".history-container");
        if(reminder_history_div)
            reminder_history_div.scrollTop(reminder_history_div[0].scrollHeight);
但是
提醒\u history\u div
不是null或为空,其对象和一些信息,检查是否为空的正确方法是什么?可能:

if(reminder_history_div.length > 0)
例如:

检查对象是否为空

jQuery.isEmptyObject({}); // true
jQuery.isEmptyObject({ foo: "bar" }); // false

检查您的内容是否为空以及是否存在

const reminder_history_div = $(".history-container").html(); //OR val() 

if(!reminder_history_div){
  console.log("empty");
} else {
    console.log("not empty");
}



if($(".history-container").length >= 1){
      console.log("exists");
    } else {
      console.log("don't exists")
    }

使用“长度”检查元素是否存在

$('.check')。单击(函数(e){
如果($('.history container')。长度>0)
console.log('Div history container exist')
其他的
console.log('Div历史记录容器不存在')
})

一些文本

检查
您试图检查它是否包含任何文本?否,仅检查是否存在类为
.history container
的对象以执行某些操作您是否尝试使用jquery选择元素,然后测试jquery是否返回了一个对象,或者您只是想检查任何javascript对象是否为空?您是否尝试了问题中的最后一行?:)我们不回答重复的问题,我们使用内置的“投票/标志”来关闭