Warrior Warrior - 1 year ago 161
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>';
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 Source

Try this when you dont want user to redirect on click

<a href="javascript: void(0)">I am a useless link</a>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download