javastudent
javastudent

Reputation: 369

remove all anchors except it's contents?

I found that sometimes this code returns NotFoundError: An attempt was made to reference a Node in a context where it does not exist.

$('a').replaceWith(function() {
    return $.text([this]);
});

Is it complaining about a case when the anchor does not have any text node? perhaps a child HTML element?

Upvotes: 2

Views: 81

Answers (1)

charlietfl
charlietfl

Reputation: 171669

Try this:

$('a').contents().unwrap()

DEMO

Upvotes: 6

Related Questions