Warrior Warrior - 2 months ago 7
HTML Question

How do I disable a href link in JavaScript?

I have a tag

<a href="#"> Previous </a> 1 2 3 4 <a href="#"> Next </a>
and in some conditions I want this tag to be completely disabled.

Code from comments (this is how the link is generated)

if (n_index != n_pages)
a = a+'<li><a href="#" onclick="javascript:paginateAjaxPage('+(n_index+1) +','+stype+');">></a></li><li><a href="#" onclick="javascript:paginateAjaxPage('+n_pages+','+stype+');" >>></a></li>';
else
a = a+'<li><a style="cursor: pointer;" onclick="return false;">></a></li><li><a style="cursor: pointer;" onclick="return false" >>></a></li>';
a = a+'</ul></div>';

Answer

Try this when you dont want user to redirect on click

<a href="javascript: void(0)">I am a useless link</a>