2

I have a code

<a href="javascript:;" class="icon-chevron-down"></a>

in my template. What the meaning? from where the *.js file function called?

Bcktr
  • 208
  • 1
  • 8
  • 22
  • It'll simply execute javascript code when link is clicked. It may be a function call (defined _somewhere_ in your HTML page or included file) or directly more complex JS code. Pretty bad but it's common and nice, for example, to write `javascript:void(0)`, somehow equivalent to your code (nothing to do). – Adriano Repetti Apr 16 '15 at 07:22
  • 1
    copnsider to read : http://stackoverflow.com/questions/1291942/what-does-javascriptvoid0-mean – Vikrant Apr 16 '15 at 07:23

2 Answers2

2

What the meaning?

javascript; is a pseudo-protocol meaning "What follows is JavaScript code". In browsers, you can use this in most places links are allowed (including bookmarks) to run code when the link is followed rather than going to a new page. (When you do it with a bookmark, it's called a "bookmarklet" — very handy.)

Your specific example:

<a href="javascript:;" class="icon-chevron-down"></a>

Defines a link that doesn't do anything (at an HTML level) when you click it, because the only JavaScript code is the ;, which is just a statement terminator. So running that code has no effect. Presumably, there's some code on that page which handles the click event on those links instead.

from where the *.js file function called?

There is no .js file in your example; the full code is ; (which doesn't do anything). If there were a function in the link instead, the function would have to already exist in the window's environment (as a global).

Example of a javascript: link that actually does something:

<a href="javascript:alert('Hi there')">Click me</a>
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
0

As far as I understand this question, javascript: mean "execute Javascript code after the :. In your case nothing is there except ;. So it has nothing to execute. It looks like a placeholder to do nothing.

It is equivalent to write href="#" or href=""

Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331