How to avoid javascript:void(0) and use an alternative in empty href links?

The javascript:void(0); attribute is used in the anchor tag (<a>) for empty links. It helps to prevent the default behavior of href links. But, JavaScript Void 0 may not work well for some JS frameworks (Angular, Backbone.js, etc) and SPA sites. Also, the content security policy (CSP) does not support javascript:void(0) in the application.

The “#!” is the most effective method to use as a javascript:void(0) alternative. Use the “#!” in the href attribute of the <a> tag for empty links.

<a href="#!">Nav Link</a>

Leave a reply

keyboard_double_arrow_up