Remove links with JavaScript in browser
If you can include jquery, you can do it simply with
$('document').ready(function (){
$('a').contents().unwrap();
});
Here's some vanilla JS that does the trick. All it does is replace a
tags with span
's and copies over class
and id
attributes (if they exist).
var anchors = document.querySelectorAll("A");
for ( var i=0; i < anchors.length; i++ ) {
var span = document.createElement("SPAN");
if ( anchors[i].className ) {
span.className = anchors[i].className;
}
if ( anchors[i].id ) {
span.id = anchors[i].id;
}
span.innerHTML = anchors[i].innerHTML;
anchors[i].parentNode.replaceChild(span, anchors[i]);
}
You can use removeAttribute
:
var allImages = document.querySelectorAll('.imageLinks');
function removehyperlinks()(){
for (var i = 0; i < allImages.length; i++) {
allImages[i].removeAttribute("href");
}
}
removehyperlinks()()