Reputation: 110163
I am trying to scroll down a page to load more content. Normally I would do the following:
window.scrollTo(0, document.body.scrollHeight);
However, I have a page where it is only a left sidebar that needs to be scrolled, and doing something like the following does not work. See image here --
How would I scroll down the left sidebar? The xpath of the containing element is: //li[contains(@class, "search-result")]
Upvotes: 0
Views: 293
Reputation: 89234
Use this:
var objDiv = document.getElementById("your_div");
objDiv.scrollTop = objDiv.scrollHeight;
Upvotes: 1
Reputation: 1974
It is similar to your approach, you can simply do
document.getElementById(YOUR_HTML_DIV).scrollTop = SCROLL_VALUE_INT;
Upvotes: 1
Reputation: 34
So here we you are scrolling 'window' to 'document.body.scrollHeight'.
window.scrollTo(0, document.body.scrollHeight);
.scrollTo() and .scrollHeight are a method/property on HTML elements. Just need to do the same thing, but with the target div as the element instead of the window/document.body. Can get it with document.findById or jQuery etc.
Upvotes: 0