/    Sign up×
Community /Pin to ProfileBookmark

Little help please?

Hi,

I need some help with this script. It works and everything, it’s just I’m using it on a big page and it keeps scrolling back to the top every time you click on a link to toggle display.

Here is the header:

<script type=”text/javascript”>
<!–
function toggle_visibility(id) {
var e = document.getElementById(id);
if(e.style.display == ‘none’)
e.style.display = ‘block’;
else
e.style.display = ‘none’;
}
//–>
</script>

And here is a link:

<a href=”#” onclick=”toggle_visibility(‘foo’);”>Show More</a><div id=”foo” style=’display:none;’>This is foo</div>

Every time this link is clicked, it will scroll back up to the top of the page as if it were a #top command. Is there any way to prevent that?

Thanks in advance.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@LeeUApr 12.2007 — Change it to this:
[CODE]
<a href="#" onclick="toggle_visibility('foo'); [COLOR="Red"]return false;[/COLOR]">Show More</a><div id="foo" style='display:none;'>[/CODE]


It stops the link from being triggered.
Copy linkTweet thisAlerts:
@gooncorpApr 12.2007 — or:
[code=html]<a href="javascript:toggle_visibility('foo');">Show More</a><div id="foo" style='display:none;'>This is foo</div>[/code]
that should also work. It's the href="#" that's scrolling to the top of the page.
×

Success!

Help @steinmeister spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...