Which of the following ways is a better way to call a js function from an a tag?
<a href="javascript:someFunction()">LINK</a>
OR
<a href="#" onclick="someFunction();" return false;">LINK</a>
I have seen this question here, but it says <span onclick="someFunction()"> is a better option. But due to some reasons I have to use <a> links.
EDIT: I am looking for a cross browser & cross platform solution which should work on androids & iPads too.
Neither is good.
Behaviour should be configured independent of the actual markup. For instance, in jQuery you might do something like
in a separate
<script>block.The advantage of this is that it
Furthermore, it degrades gracefully (but so would using the
onclickevent) since you can provide the link tags with ahrefin case the user doesn’t have JavaScript enabled.Of course, these arguments still count if you’re not using jQuery or another JavaScript library (but why do that?).