Reputation: 907
I have a DIV which is limited in height, and has a scrollable overflow. I would like to add two manual scroll links that when they are clicked, the content inside the DIV scrolls up or down.
CSS
#inner {
max-height: 400px;
overflow: scroll;
}
JS
function scrolldown() {
document.getElementById('#inner').scrollTop -= 10;
}
function scrollup() {
document.getElementById('#inner').scrollTop += 10;
}
HTML
<div id="inner">
Looooong content here
</div>
<a href="#" onClick="return false" onmousedown="javascript:scrollup();">
<img src="up.png"/>
</a>
<a href="#" onClick="return false" onmousedown="javascript:scrolldown();">
<img src="down.png"/>
</a>
However it does not really work ...
Upvotes: 2
Views: 2970
Reputation: 2750
You can't use CSS selector in getElementById
.
function scrolldown() {
document.getElementById('inner').scrollTop -= 10;
}
function scrollup() {
document.getElementById('inner').scrollTop += 10;
}
Upvotes: 4
Reputation: 1362
You used a double selector, getElementById
does not need the #
in its argument. And if you put the javascript between the <head>
tags it should work fine.
function scrolldown() {
document.getElementById('inner').scrollTop -= 10;
}
function scrollup() {
document.getElementById('inner').scrollTop += 10;
}
Upvotes: 1