Archive

Archive for December, 2009

Disable All Links Within DIV

December 14th, 2009 5:00 pm by John Dalesandro No comments

This JavaScript function will disable all links within the specified DIV by setting the link object to ‘disabled’ as well as removing the ‘onclick’ and ‘href’ attributes. This is a useful JavaScript function for form submissions since it will help prevent the user from clicking another link while an action is pending.

function DisableAllDIVLinks(DivId) {
  var div = document.getElementById(DivId);
  var anchorList = div.getElementsByTagName('a');
 
  for(var i = 0; i < anchorList.length; i++) {
    anchorList[i].disabled = true;
    anchorList[i].onclick = '';
    anchorList[i].removeAttribute('href');
  }
}
Categories: Computing Tags: ,