Click here to get back home

proper ways for empty link

 HomeNewsGroups | Search | About
 comp.infosystems.www.authoring.html    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
proper ways for empty link Xah Lee 11-18-2005
Get Chitika Premium
Posted by Xah Lee on November 18, 2005, 2:53 pm
Please log in for more thread options


if i want to have a empty link, which way is more proper?

<a href=3D"">
<a href=3D"#">
<a href=3D"javascript:void(0);">

Xah
xah@xahlee.org
=E2=88=91 http://xahlee.org/


Posted by VK on November 18, 2005, 3:06 pm
Please log in for more thread options



Xah Lee wrote:
> if i want to have a empty link, which way is more proper?
>
> <a href="">
> <a href="#">
> <a href="javascript:void(0);">

You may want to read this extensive (and rather intensive) discussion
on this very question here:
<http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/4d2e99b2a8bdbbd2/b595a7a81b0a62a3>

>From the *listed* options I personally would stay with:
<a href="javascript:void(myFunction())">

<a href=""> and <a href="#"> will lead to page shift/scroll if the page
is long enough on older browsers.


Posted by Matt Kruse on November 18, 2005, 5:38 pm
Please log in for more thread options


VK wrote:
>> From the *listed* options I personally would stay with:
> <a href="javascript:void(myFunction())">

Of the listed options, this is the _worst_.

There is no reason to use this as opposed to:
<a href="javascript_required.html" onClick="myFunction(); return
false;">link</a>

See "Using onClick in <A> tags" in
http://www.JavascriptToolbox.com/bestpracties/

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com



Posted by Nick Theodorakis on November 19, 2005, 4:18 pm
Please log in for more thread options


On Fri, 18 Nov 2005 17:38:49 -0600, "Matt Kruse"

>
>
>See "Using onClick in <A> tags" in
>http://www.JavascriptToolbox.com/bestpracties/
>

Typo. Try:

< http://www.javascripttoolbox.com/bestpractices/ >

Nick

--
Nick Theodorakis
nick_theodorakis@hotmail.com
contact form:
http://theodorakis.net/contact.html

Posted by Jukka K. Korpela on November 18, 2005, 11:03 pm
Please log in for more thread options



> if i want to have a empty link, which way is more proper?

Why would you want to have an empty link?

> <a href="">

This is a reference to the document itself.

> <a href="#">

This is a reference to the start of the current document.

> <a href="javascript:void(0);">

This is undefined; javascript: URLs are unregistered.

You could create a self-referencing link, too:
<a name="foo42" href="#foo42">

I suppose you want to have an "empty" link so that you can make something
clickable, triggering some scripted events, without making it a link.
The simple answer is: don't.

Make it a link that points to an address that contains a useful replacement
for the functionality, if it is relevant.

<a href="#nojs" onclick="foo(); return false">
. . .
<h2 id="nojs">Something</h2>
<p>Put here something useful.</p>

If your piece of HTML code has been _generated_ with JavaScript, so that the
element does not appear if JavaScript is off, use href="#" but make sure your
event handler returns false, so that the href will never be used (it could be
harmful if it caused a movement to the start of the document).

--
Yucca, http://www.cs.tut.fi/~jkorpela/
Pages about Web authoring: http://www.cs.tut.fi/~jkorpela/www.html


Similar ThreadsPosted
Empty link August 28, 2005, 12:33 pm
many ways to import page June 16, 2005, 12:01 pm
5 Sure Fire Ways To Get Radio Play For Your "Independent" Music! January 29, 2008, 11:29 pm
Proper use of HTML and CSS August 5, 2005, 3:09 pm
Proper code for input tag July 26, 2004, 8:09 pm
Proper alternative for iframe October 1, 2008, 4:47 am
Proper use of cite tag for magazine articles. July 12, 2004, 5:20 pm
two images in one row with proper spaces and without tables September 5, 2008, 7:46 pm
Empty Alt Tags April 1, 2005, 3:16 pm
Empty fragment July 7, 2005, 10:10 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap