Corentin Branquet
Corentin Branquet

Reputation: 1576

Remove content after link

I've this code :

<span>
   <a href="#">Hello world</a>
   »
</span>

I want delete » after the link.

I try this but it does not work.

jQuery(function ($) {

   $('span a').nextAll('»').remove();

});

Thanks for the help !

Upvotes: 0

Views: 63

Answers (3)

Arun P Johny
Arun P Johny

Reputation: 388316

One solution si to delete the last child of the span for that

$('span').contents().last().remove()

jQuery(function($) {
  $('button').click(function(){
    $('span').contents().last().remove();
  })
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<button>Remove</button>
<span>
   <a href="#">Hello world</a>
   »
</span>


To delete the next sibling of a

$($('span a')[0].nextSibling).remove()

Upvotes: 1

stanze
stanze

Reputation: 2480

Try this Demo, by the help of text node.

$("span").contents().filter(function () 
    {
       return this.nodeType != 1;
    })
.remove();

Upvotes: 2

G.L.P
G.L.P

Reputation: 7207

You can try like this with only css: Demo

<span>
   <a href="#">Hello world</a>
    <span> » </span>
</span>

CSS:

span>span{
   display:none;

}

Upvotes: 0

Related Questions