Reputation: 31840
Using JavaScript, is it possible to convert a hyperlink to plain text (so that it no longer links to any page?)
For example, would it be possible to change the following link (inside the <a>
tag) to plain text using JavaScript (so that this text no longer links to any page)?
<html>
<body>
<a href="http://www.wikipedia.org/" target="blank" id = "wikiLink">Go to Wikipedia</a>
</body>
</html>
Upvotes: 0
Views: 5434
Reputation: 90804
With jQuery a simple way is to remove the link and to put a text node instead:
var $link = $('#wikiLink');
$link.after($link.text());
$link.remove();
Upvotes: 0
Reputation: 1741
Following code should render hyper link as text.
$(element).find('a').contents().unwrap();
Upvotes: 3
Reputation: 66693
If you want to remove the "link" behavior of all links, you can do:
var links = document.getElementsByTagName('a');
for(var i=0; i<links.length; i++) links[i].href = '';
Upvotes: 0
Reputation: 1505
document.getElementById("wikiLink").removeAttribute('href')
or with jquery
$("#wikiLink").removeAttr('href');
Upvotes: 3
Reputation: 324750
The simplest way would be to remove its href
attribute:
document.getElementById('wikiLink').removeAttribute("href");
If you want to completely remove the node, leaving the text, try this:
var toRemove = document.getElementById('wikiLink'), parent = toRemove.parentNode,
text = toRemove.firstChild;
parent.insertBefore(text,toRemove);
parent.removeChild(toRemove);
parent.normalize();
Upvotes: 3