Possible Duplicates:
Href for Javascript links: “#” or “javascript:void(0)”?
Why is it bad practice to use links with the javascript: “protocol”?
As question says . .
Which approach is better ?
<a href='javascript:func()' >blah</a>
or
<a href='#' onclick='func()' >blah</a>
Adding onclick dynamically The example above works, but is generally considered bad practice. Instead, it's better to separate the content of the page (HTML) from the logic (JS).
In JavaScript, you can call a function or snippet of JavaScript code through the HREF tag of a link. This can be useful because it means that the given JavaScript code is going to automatically run for someone clicking on the link. HREF refers to the “HREF” attribute within an A LINK tag (hyperlink in HTML).
Using onclick Event: The onclick event attribute works when the user click on the button. When mouse clicked on the button then the button acts like a link and redirect page into the given location. Using button tag inside <a> tag: This method create a button inside anchor tag.
The anwer is: not possible.
Neither.
Use this:
<a href="javascript-disabled-page" onclick="func(); return false;">blah</a>
That way if the user has JS disabled, they will be taken to javascript-disabled-page
and the browsing experience isn't ruined.
That depends on what you want to achieve. From a SEO perspective it's better to use links only for actual links, and use click events on other tags for things that doesn't navigate anywhere:
<span class="LinkLookalike" onclick="func();">blah</span>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With