canadadry
canadadry

Reputation: 8443

Is this href value equivalent to "javascript:void(0)"?

What is the difference between javascript:// and javascript:void(0) ?

<a href="javascript://" class="button toggle-filters">Filters</a>

Upvotes: 3

Views: 777

Answers (2)

cori
cori

Reputation: 8830

Previous two answers cover the direct answer to your question, but on a separate track I think you should consider using neither of them. Assuming you're using the anchor tag to illustrate to the user that there's an action they can take by clicking on that text, there are multiple mechanisms for illustrating that, and semantically an anchor tag should illustrate a destination, not an activity.

See this previous answer, and this one.

Upvotes: 2

Harsh Baid
Harsh Baid

Reputation: 7249

javascript:// runs JavaScript that has no statements

javascript:void(0) runs JavaScript that evaluates the statement 0 and then returns undefined.

so javascript:// is much similar to javascript:;

Neither should be used.

Upvotes: 2

Related Questions