Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
53
rated 0 times [  58] [ 5]  / answers: 1 / hits: 57669  / 14 Years ago, thu, august 12, 2010, 12:00:00

There is a javascript-based interface - so I need not to support work without javascript.



I have an



<a>Something</a>


elements with JS code, which binds on click event - so, I don't want page reload after user's click.



Which way is better?



1. <a href=javascript:void(0)>Something</a>
2. <a href=# onclick=return false;>Something</a>


What advantages and disadvantages of each method?


More From » javascript

 Answers
70

Both are poor choices. Presentation shouldn't mix with content. That means no javascript: URIs, and definitely no onclick attributes.



The way to do it:



<a id=myLink>Something</a>
<script>
function myFunction(...) { ... }
document.getElementById('myLink').addEventListener('click', myFunction, false);
</script>

[#95943] Tuesday, August 10, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tyriquehenryq

Total Points: 248
Total Questions: 81
Total Answers: 105

Location: Bermuda
Member since Thu, Apr 20, 2023
1 Year ago
tyriquehenryq questions
;