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!
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!
Share Improve this question edited May 23, 2017 at 11:52 CommunityBot 11 silver badge asked May 23, 2012 at 16:41 richierichie 8012 gold badges13 silver badges24 bronze badges 3- What text do you want to keep? Within which one? – debianek Commented May 23, 2012 at 16:45
- Thank you everyone, very quick responses! debianek, The txt I wanted to keep was Call 1. I have the answer now but thank you for asking. – richie Commented May 23, 2012 at 17:07
- Possible duplicate: stackoverflow.com/questions/2556051/… – Anderson Green Commented Feb 27, 2013 at 3:24
6 Answers
Reset to default 8Yes, 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]);
});
You can do this easily with the following code and jQuery will handle looping through all a
and replace those with the text within.
$('#Summary a').contents().unwrap();
Working Fiddle
$.unwrap()
try this:
$('th a').each(function(){
$(this).replaceWith($(this).text())
})
I haven't tested for syntax correctness, but, something along these lines should work:
$('#Summary a').each( function() {
$(this).parent().html($(this).html());
}
$("#Summary").find('a').each(function(){
$(this).attr('href','#');
});
I believe this will solve your purpose.
$('.surveyTable tr th a, .surveyTable tr td a').each(function(){
$(this).replaceWith($(this).text());
});
http://jsfiddle.net/qTB8E/3/