Click to See Complete Forum and Search --> : div scroll/name/anchor


demo
11-12-2003, 03:04 PM
hi,

does any know how to 'jump' inside divs.

for example on a normal page you would write

<a href="#dogs">click for dogs</a>

...
...
...

<a name="dogs">The dog section</a>

but how do you do it in a div, i realise this is kind of a html question but there may be a javascript way to do it?

cheers,

demo

Mr J
11-13-2003, 11:04 AM
Please try the following



<HTML>
<HEAD>
<TITLE>Document Title</TITLE>

<SCRIPT language="javaScript">
<!--
function go_anchor(n){
document.getElementById("div1").scrollTop = document.getElementById(n).offsetTop
}
// -->
</script>
</HEAD>
<BODY >
<a href="#null" onclick="go_anchor('sp1')">To anchor 1</a><BR>
<a href="#null" onclick="go_anchor('sp2')">To anchor 2</a><BR>
<a href="#null" onclick="go_anchor('sp3')">To anchor 3</a><BR>
<a href="#null" onclick="go_anchor('sp4')">To anchor 4</a><BR>
<div id="div1" style="position:absolute; left:30; top:100; width:330; height:200; clip:rect(0,330,200,0); overflow:auto; padding:5;border:2px solid black">
<P><a href="#null" onclick="go_anchor('sp1')">To anchor 1</a>
<P>Dummy Text 2
<P>Dummy Text 3
<P>Dummy Text 4
<P>Dummy Text 5
<P>Dummy Text 6
<P>Dummy Text 7

<P><span id="sp1">Anchor 1</span>

<P>Dummy Text 9
<P>Dummy Text 10
<P>Dummy Text 11
<P>Dummy Text 12
<BR><BR><BR><BR><BR>

<span id="sp2">Anchor 2</span>

<BR><BR><BR><BR><BR>

<span id="sp3">Anchor 3</span>

<BR><BR><BR><BR><BR>

<span id="sp4">Anchor 4</span>

<BR><BR><BR><BR><BR>
<BR><BR><BR><BR>
The End
</div>

</BODY>
</HTML>

demo
11-13-2003, 12:30 PM
thank you so much it worked!

:D

cheers again,

demo