Perferred way to attach codes into hyperlink?

H

howa

I know some people might argue to use the style like...

document.getElementById("link1").onclick = function () {...

but attach the function into the link directly is more handy and easy
to maintain (i.e. when you delete the link, no codes left behind, and
easy to check what is happening with the link)



anyway, which method you preferred below?

1.

<a href="#" onclick="test()" />

2.

<a href="javascript:test()" />


3.

<a href="javascript:;" onclick="test()" />


4.

<a href="javascript:void(0)" onclick="test()" />

5.

any others?
 
L

Lee

howa said:
I know some people might argue to use the style like...

document.getElementById("link1").onclick = function () {...

but attach the function into the link directly is more handy and easy
to maintain (i.e. when you delete the link, no codes left behind, and
easy to check what is happening with the link)



anyway, which method you preferred below?

1.

<a href="#" onclick="test()" />

2.

<a href="javascript:test()" />


3.

<a href="javascript:;" onclick="test()" />


4.

<a href="javascript:void(0)" onclick="test()" />


None of the above is acceptable.
See the FAQ
http://www.jibbering.com/faq/#FAQ4_24


--
 
S

scripts.contact

howa said:
anyway, which method you preferred below?
1.
<a href="#" onclick="test()" />

2.
<a href="javascript:test()" />

3.
<a href="javascript:;" onclick="test()" />

4.
<a href="javascript:void(0)" onclick="test()" />

5.

<button onclick="test()">Run Test Function</button>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top