Peter Worsky
Peter Worsky

Reputation: 87

Scroll to down in div (in Firefox and IE!)

<div id="aaa">sdfas fasdfa asdfsdfas fasdfa asdfsdfas fasdfa asdfsdfas fasdfa asdfsdfas fasdfa asdfsdfas fasdfa asdfsdfas fasdfa asdfsdfas fasdfa asdfsdfas fasdfa asdfsdfas fasdfa asdfsdfas fasdfa asdfsdfas fasdfa asdfsdfas fasdfa asdfsdfas fasdfa asdfsdfas fasdfa asdfsdfas fasdfa asdfsdfas fasdfa asdfsdfas fasdfa asdfsdfas fasdfa asdf </div>

#aaa {
height: 100px;
    width: 200px;
    overflow: scroll;
}

$("#aaa").scrollTop = $("#aaa").scrollHeight;  

http://jsfiddle.net/PfA7Q/2/

Is possible doing scroll to down in this DIV in Firefox and in IE?

Upvotes: 0

Views: 1441

Answers (2)

Bhesh Gurung
Bhesh Gurung

Reputation: 51030

$("#aaa").attr({ scrollTop: $("#aaa").attr("scrollHeight") });

Replace attrs with prop for jQuery 1.6+.

Upvotes: 0

Leo
Leo

Reputation: 5286

Your code is a bit wrong, as scrollTop in jQuery is actually a function, not a property. And scrollHeight is a native javascript property, not related to jQuery. So you'll want to do something like this :

$('#aaa').scrollTop($("#aaa")[0].scrollHeight);

http://jsfiddle.net/PfA7Q/14/

That being said, you should probably cache your div reference in a variable instead of getting it two times, like this :

var $aaa = $('#aaa');
$aaa.scrollTop($aaa[0].scrollHeight);

Upvotes: 2

Related Questions