How can I disable all hyperlinks in a div element? I don't want any active links in my div(editable). Please help me. Thanks in advance
A:
First grab all the links.
var links = editable.getElementsByTagName('a'); // where "editable" is a var pointing to your div
Then set the onclick to false.
for (var i = 0; i < links.length; i++) {
var link = links[i];
link.onclick = function() { return false; };
}
TRiG
2010-09-20 09:11:43
A:
using javascript you can write a simple method as given below -
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<end; i++) {
anchors[i].onclick = function() {
return false;
};
}
}
}
//Call to function as
disableLinksByElement('mydiv');
Sachin Shanbhag
2010-09-20 09:12:22
+1
A:
jQuery:
$("#myEditableDiv a").click(function(){ return false; });
Dan Atkinson
2010-09-20 09:13:54
+1 jQuery is the best.
jostster
2010-09-20 17:13:38