I want to disable all href links in my page. i am using the below code and it is working fine only in IE.
var elems = document.getElementsByTagName("*");
var len = elems.length;
for (i=0; i<len; i++) {
if(elems[i].tagName.toLowerCase() == 'a'){
elems[i].disabled = true;
}
}
but i want work it on all browsers. can somebody please help me how to overcome this issue.
Thanks in advance.
If you don't want to change the href of the links, one could do this too:
window.onload = function() {
var anchors = document.getElementsByTagName("a");
for (var i = 0; i < anchors.length; i++) {
anchors[i].onclick = function() {return false;};
}
};
Working demo here: http://jsfiddle.net/jfriend00/9YkJQ/.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With