'What is meant by javascript:// in the href of a link

Yesterday, I visited a forum. There was like and Dislike button under the each post. When I click the Like button, the Like was counted without any page reload. Meaning Ajax was working, but when I check the href of that like link that was like this:

<a href="javascript://" name="dbtech_thanks_button" data-postid="1369522" data-button="likes" style="padding-right:6px;"><img src="dbtech/thanks/images/likes.png" alt="Likes" title="Likes"> Like</a>

I have also checked (using Visual Event) that there is no event listener attached to that link. So, I cant understand that how it works. Can some one explain?



Solution 1:[1]

javascript: return 0;

Does the same thing.

This would just uselessly create a random regular expression literal and then discard it. It is probably some programmer's ignorance.

This is included because an a tag has to have an href.

Solution 2:[2]

On its own, a link with href="javascript://" does nothing at all when clicked. This is as opposed to a link with href="#", which will set the anchor of the current location to #, or a blank or unset href, which will cause navigation to the current page.

In this case, since there's no explicit onclick handler and no event handler attached to this link, there must be some a event handler at a higher level that's catching click events as they bubble up to the page. Without being able to see the site, it's impossible to say for sure how it's working, but my guess would be that the data-button="likes" attribute is involved here.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 tckmn
Solution 2