-3

I am new to JavaScript and come across the usage of 'javascript:void(0)' in this post: What does "javascript:void(0)" mean?

If 'javascript:void(0)' is used in the below manner:

<a href="JavaScript:void(0);" ondblclick="alert('Well done!')">Double Click Me!</a>

then I understand the purpose of "JavaScript:void(0);" is just to prevent the page from refreshing, and the real action is in "ondblclick="alert('Well done!')".

However, if 'javascript:void(0)' is used in the below manner:

<a href="javascript:void(0)" id="loginlink">login</a>

then what's really happening? Where do I find the code, if it is JavaScript, that gets executed when this link is clicked?

An example is the Google image search page at: https://www.google.com.au/imghp?hl=en&tab=wi&ei=eLb0VYb4MuOxmwXe97SICg&ved=0CBMQqi4oAQ

Screen shots attached below:

enter image description here

<a class="gsst_a" href="javascript:void(0)" aria-label="Search by image"><span id="gs_si0"><span class="gsst_e" id="qbi"></span></span></a>

In this case, where is the actual code to execute after I click the "Search by image" link?

halfer
  • 19,824
  • 17
  • 99
  • 186
user1559625
  • 2,583
  • 5
  • 37
  • 75
  • 3
    They've registered an event listener somewhere that will fire on click. For example, `document.getElementById('someId').addEventListener('click', function() { ... });` – Tom Sep 13 '15 at 01:14
  • Examples of event binding http://stackoverflow.com/questions/9462605/how-to-bind-event-to-element – Jan Sep 13 '15 at 01:16

1 Answers1

0

This question is answered at What does `void 0` mean?

void takes one argument and returns undefined. The argument can be anything, but for consistency you should use 0.

Community
  • 1
  • 1
tph
  • 326
  • 3
  • 5
  • *"where do I find the code, if it is javascript, that gets executed when this link is clicked?"* – nnnnnn Sep 13 '15 at 01:20
  • @user1559625 The `javascript:void(0)` doesn't execute any javascript other than what you can see, it forces the page to not load. – tph Sep 13 '15 at 01:36
  • @user1559625 The `javascript:void(0)` doesn't execute any javascript other than what you can see, it forces the page to not re-load. In the google example there is an event handler (listener) which executes when the button is clicked. You can view it by finding the section of 'event listeners' in developer tools, then go down to 'click' – tph Sep 13 '15 at 01:42