How do I disable a href link in JavaScript?

Warrior picture Warrior · Mar 21, 2011 · Viewed 368k times · Source

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

Pranay Rana picture Pranay Rana · Mar 21, 2011

Try this when you dont want user to redirect on click

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