Disable and enable all hyperlinks inside a div using javascript
Disable and enable all hyperlinks inside a div using javascript
Simple javascript that disable and enable all the hyperlinks inside a div tag. Interesting right. Here is the script that disable all links. You need to pass the function accordingly. Say for example if you have a div tag with id=”main” then you can disable all the hyperlinks inside the div tag by passing disableLinksByElement(main).
The html will look like this.
<div id="main"> <!-- Your Hyperlinks --> </div> <a href="javascript:disableLinksByElement(main)">Disable All Links</a>
Make sure that your “Disable All Links” Hyperlink is outside the div tag with id=”main”
function disableLinksByElement(el) {
if (document.getElementById && document.getElementsByTagName) {
if (typeof(el) == ‘string’) {
el = document.getElementById(el);
}
var anchors = el.getElementsByTagName(‘a’);
for (var i=0, end=anchors.length; i
[/html]
function enableLinksByElement(el) {
if (document.getElementById && document.getElementsByTagName) {
if (typeof(el) == ‘string’) {
el = document.getElementById(el);
}
var anchors = el.getElementsByTagName(‘a’);
for (var i=0, end=anchors.length; iIncoming search terms: