Javascript DIV向下滚动到底部脚本错误JQUERY

Javascript DIV向下滚动到底部脚本错误JQUERY,javascript,jquery,Javascript,Jquery,我从这个函数收到一个错误 function scrolldown() { $("#chatArea").scrollTop($("#chatArea")[0].scrollHeight); } Fehler:TypeError:$(…)[0]未定义 在ajax查询中调用此脚本以更新聊天框以滚动到底部 function refreshChat() { $.ajax({ type: "POST", url: "ajax/sb.php

我从这个函数收到一个错误

function scrolldown() {
$("#chatArea").scrollTop($("#chatArea")[0].scrollHeight);
}
Fehler:TypeError:$(…)[0]未定义

在ajax查询中调用此脚本以更新聊天框以滚动到底部

function refreshChat()
{       
      $.ajax({
          type: "POST",
          url: "ajax/sb.php",
           success: function(msg){
                $("#chatArea").html(msg);
                scrolldown();
           }
      });
}
每5秒更新一次

window.setInterval("refreshChat()",5000);

有什么建议吗?

我认为这应该行得通

function scrolldown() {
    $("#chatArea").scrollTop(document.getElementById('chatArea').scrollHeight);
}
去掉使用
$(“#chatArea”)[0]
将返回带有jQuery的dom元素这一事实。但不管出于什么原因,它似乎返回了一个错误

编辑

我的答案已修复了原始问题,但您已更新为:

 TypeError: document.getElementById(...) is null 
这基本上意味着找不到元素。简而言之,当函数运行时,
$(“#chatArea”)
不在DOM中。它不存在。请确保运行该函数时,
$(“#聊天区”)
可用。

尝试此操作

function scrolldown() {
    $("#chatArea").scrollTop($("#chatArea").get(0).scrollHeight);
}

你想用这美元(“#聊天区”)[0]做什么??正确的是$(“#chatArea”)。查找(0)@Guerra
$(“#chatArea”)[0]
将返回DOM元素而不是jQuery对象。@Guerra您错了,他的解决方案是正确的。
console.log($(“#chatArea”).size())
的输出是什么?可能您在
#chatArea
中有输入错误,您确定您有。。。在html中?只是一个旁注,您不需要添加[0],因为您正在选择一个id。假设您没有复制您的id,这是相同的问题>Fehler:TypeError:$(…)。get(…)是未定义的问题与以前一样我认为它可以工作,但后来我查找时Zeitstempel:01.10.2013 18:42:29 Fehler:TypeError:document.getElementById(…)为空