2

This code gives errors in the W3 Validator, however it does the job on click.

<span href="#" class="click">+</span>

If I convert it to the code below it validates in the W3 but on click the pointer moves up, on the screen. It does not stay on the "+"

<a href="#" class="click">+</a>

What is wrong with it?

merxie
  • 95
  • 10

3 Answers3

3

please use a <button> instead of <a> if you don't want to provide a link!

a <button> element is exactly what you want, because the <a> tag is for links and a href="#" would trigger a jump to top.

mador
  • 1,203
  • 9
  • 13
2

To avoid click jumps on anchor tags, remove hash and add javascript:; instead, like below:

<a href="javascript:;" class="click">+</a>
Sanjeev Kumar
  • 3,113
  • 5
  • 36
  • 77
  • why messing around with inline js? just use a ` – mador Jan 28 '17 at 10:17
  • I have suggested the answer as per the question, OP was facing click jumps problem, so I just suggested him that, changing the tag is his decision. – Sanjeev Kumar Jan 28 '17 at 10:20
  • sure, but the "click jump problem" is the result of using the wrong tag for this case :) – mador Jan 28 '17 at 10:33
0

you can also use this way.

<a href="javascript:void(0)"; class="click">+</a>

you refer more here

Community
  • 1
  • 1
Yonas Hailu
  • 853
  • 7
  • 20