2

For example:

<a href="/" title="Go to homepage">Homepage</a> text after link;
<a href="/" title="About">About</a> text after link;
<a href="/" title="Contact Us">Contact Us</a> text after link;

No problem: I can remove the link with:

$("a:contains('Homepage')").remove();

My question: How to remove the text after the link previously removed:

text after link

Thanks in advance.

Nick Craver
  • 623,446
  • 136
  • 1,297
  • 1,155
josoroma
  • 1,887
  • 2
  • 14
  • 16

1 Answers1

4

You can set that text node's value to empty, like this:

$("a:contains('Homepage')")[0].nextSibling.nodeValue = "";

You can try it here. If you're unsure if it's there, add an if check, like this:

var node = $("a:contains('Homepage')")[0];
if(node && node.nextSibling) node.nextSibling.nodeValue = "";
Nick Craver
  • 623,446
  • 136
  • 1,297
  • 1,155