<ul id="boxinoamicizie">
<li class="first">from
<a href="users/valerio">valerio</a>
(<a href="#">Approve</a>|<a href="#">Disapprove</a>)
</li>
<li>from
<a href="users/federico">federico</a>
(<a href="#">Approve</a>|<a href="#">Disapprove</a>)
</li>
<li class="last">from <a href="users/federico">federico</a>
(<a href="#">Approve</a>|<a href="#">Disapprove</a>)
</li>
</ul>
i need to remove “from” and leave the rest of the string i tried to use
$('.item-list ul li').each( function(){
var text = this.textContent;
this.textContent = text.replace( /from/g, "" );
});
but it cancel me “from” and the links from the html code
can somebody give me some help?
EDIT:
the result i need is
<ul id="boxinoamicizie">
<li class="first">
<a href="users/valerio">valerio</a>
(<a href="#">Approve</a>|<a href="#">Disapprove</a>)
</li>
<li>
<a href="users/federico">federico</a>
(<a href="#">Approve</a>|<a href="#">Disapprove</a>)
</li>
<li class="last">
<a href="users/federico">federico</a>
(<a href="#">Approve</a>|<a href="#">Disapprove</a>)
</li>
</ul>
Iterate over the text nodes and remove it if it contains
from:DEMO
The reason why
this.textContent = this.textContent.replace( /from/g, "" )does not give the desired result is simple:.textContentreturns the text of the element and all descendants, i.e. you getFrom that string you are removing
fromand then reassign the result as content to the element. This will replace the current content of the element.You could use
$(this).html()instead to work with the HTML content of the element, but if you have event listeners registered with the links, they will be destroyed, as you are destroying and recreating DOM elements.