-4

Please I have seen some people use this "javascript:" in some href attribute of an a tag. Please my question is what is the purpose of that in the in the a tag. Thus does that ensure that the clicking on the a tag sends the function of the click to javascript to handle instead of the DOM OR WHAT IS THE REAL PURPOSE OF IT. ( JAVASCRIPT:)

Kiran Joshi
  • 1,758
  • 2
  • 11
  • 34
Abcaha
  • 9
  • 2
  • The `javascript:` protocol evaluates and executes the proceding string as JavaScript, e.g. `href="javascript:alert('hello');"`. It's rarely used; rather, events are handled centrally in a dedicated .js file. – Mitya Jul 20 '18 at 10:42

1 Answers1

3

In short: it executes JavaScript when clicking on the link:

<a href="javascript:console.log('Click!')">Click me please!</a>
CodeF0x
  • 2,624
  • 6
  • 17
  • 28