3

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!

3
  • What text do you want to keep? Within which one? 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. Commented May 23, 2012 at 17:07
  • Possible duplicate: stackoverflow.com/questions/2556051/… Commented Feb 27, 2013 at 3:24

6 Answers 6

8

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]);
});
Sign up to request clarification or add additional context in comments.

1 Comment

OP didnt ask for that, but if you just want to remove those links just do . . . .. . . .. . .. $('#yourCssSelector a').remove(); ;)
7

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()

Comments

2

try this:

$('th a').each(function(){
   $(this).replaceWith($(this).text())
})

Comments

0

I haven't tested for syntax correctness, but, something along these lines should work:

$('#Summary a').each( function() {
   $(this).parent().html($(this).html());
}

Comments

0
$("#Summary").find('a').each(function(){
  $(this).attr('href','#');
});

I believe this will solve your purpose.

Comments

0
$('.surveyTable tr th a, .surveyTable tr td a').each(function(){
   $(this).replaceWith($(this).text());
});​

http://jsfiddle.net/qTB8E/3/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.