If you need to do it on a script instead of a unique element, you can do something like this:
var a_nodes_list = document.getElementsByTagName("a");
for(var i = 0; i < a_nodes_list .length; i++) {
a_nodes_list[i].onclick = function() { return false; };
}
var a_nodes_list = document.getElementsByTagName("a");
for(var i = 0; i < a_nodes_list .length; i++) {
a_nodes_list[i].onclick = function() { return false; };
}
<a href="http://google.es">Link</a>
<a href="http://google.es">Link</a>
<a href="http://google.es">Link</a>
<a href="http://google.es">Link</a>
<a href="http://google.es">Link</a>
<a href="http://google.es">Link</a>
<a href="http://google.es">Link</a>
<a href="http://google.es">Link</a>
<a href="http://google.es">Link</a>
<a href="http://google.es">Link</a>
With document.getElementsByTagName("a")
recover every anchor
tag on the document. So just iterate through nodes and apply a handler for the onclick
event to return false on every a
node.
About the second request of your question related to use an alert box to say is unclickable we just need to modify our litte script:
var a_nodes_list = document.getElementsByTagName("a");
for(var i = 0; i < a_nodes_list.length; i++) {
a_nodes_list[i].onclick = function() { return false; };
a_nodes_list[i].onmouseover = function() { alert("UNCLICKABLE"); };
}
var a_nodes_list = document.getElementsByTagName("a");
for(var i = 0; i < a_nodes_list.length; i++) {
a_nodes_list[i].onclick = function() { return false; };
a_nodes_list[i].onmouseover = function() { alert("UNCLICKABLE"); };
}
<a href="http://google.es">Link</a>
<a href="http://google.es">Link</a>
<a href="http://google.es">Link</a>
<a href="http://google.es">Link</a>
<a href="http://google.es">Link</a>
<a href="http://google.es">Link</a>
<a href="http://google.es">Link</a>
<a href="http://google.es">Link</a>
<a href="http://google.es">Link</a>
<a href="http://google.es">Link</a>
We just simply add alert("UNCLICKABLE");
on the hover event of every anchor element.