/    Sign up×
Community /Pin to ProfileBookmark

Clickable link that doesn’t refresh page or load another

Hi, I want to be able to create a button on my site that the mouse cursor recognises as a link, but that doesn’t load a page or reload the current page when clicked.

I just want it to run a bit of javascript.

Can anyone suggest anything. I could use a styled button, but they have cross-browser issues.

Thanks in advance.

to post a comment
HTML

3 Comments(s)

Copy linkTweet thisAlerts:
@coldscooterauthorSep 30.2009 — The thumbs-up/thumbs-down links on youtube comments are a good example.
Copy linkTweet thisAlerts:
@nathandelaneOct 01.2009 — One thing you could do is in the href attribute of a regular link (also known as an anchor tag), write javascript code, like:
<i>
</i>&lt;a href="javascript:return false;"&gt;Link text&lt;/a&gt;


Or you could use CSS to style a different kind of HTML element to appear like a link when the mouse cursor hovers over it, like:
<i>
</i>&lt;img src="/images/some-image-file-name.png" style="cursor: pointer;"/&gt;
Copy linkTweet thisAlerts:
@coldscooterauthorOct 01.2009 — That is pefect. Thanks for the reply.
×

Success!

Help @coldscooter 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 6.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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...