0

What is the purpose of javascript:; in the href attributes of the hyperlinks?

<div data-trigger="spinner" id="spinner">
   <span id="spinner-value"></span>
   <input type="hidden" value="1" data-spin="spinner" data-rule="quantity" data-max="10">
   <a href="javascript:;" data-spin="down">-</a>
   <a href="javascript:;" data-spin="up">+</a>
</div>
Sᴀᴍ Onᴇᴌᴀ
  • 8,218
  • 8
  • 36
  • 58
Manoj A
  • 325
  • 3
  • 6
  • 13

3 Answers3

2

the attribute href="javascript:;" is used to remove the behavior from the link.

If you would use eg. href="", the webpage would reload when you click the link. But with href="javascript:;" nothing will happen.

Later a script adds an event handler that will be executed when clicking this link.

EDIT: You need a or button elements as they are the semantic representatives for clickable objects.

MEE
  • 503
  • 1
  • 11
  • 21
1

To prevent links from refreshing webpage/redirecting you once clicked.

1

the purpose of "javascript:;" have save meaning with "javascript:void(0)"

Read here : javascript void functions

Luki Centuri
  • 185
  • 1
  • 6