How do I use JQuery or JavaScript to remove all links in a table?
javascript, jquery
Solution
Yes, that should be fairly simple, using the function callback signature of `replaceWith`:
$('#summary a').replaceWith(function() {
return this.childNodes;
});
That removes each `a` element and replaces each one with all of its child nodes. This means that you keep any formatting.
If you wanted to just have plain text, that would also be easy to achieve:
$('#summary a').replaceWith(function() {
return $.text([this]);
});
Problem
I have a table that I would like to export to Excel but I don't want any of the hyperlinks to come through. Is that possible? I noticed that something similar was being done in the thread JQuery remove images but I don't thing it quite the same as what I need? I would also like to keep the text within the tag if possible? Example: ``` <table class="surveyTable" id="Summary"> <tr> <th>Section</th> <th title="3584"> <a href="test.php?id=3584"> Call 1 </a> </th> ... ``` I would like to have the ability to export the above without the href yet retaining the "Call 1" but maybe this is not possible? Thanks!