Reputation: 6192
My HTML looks something like this:
<b><a href="#">Home</a> > <a href="#">This Page</a></b>
How can I replace all instances of the plain text right-angle brackets >
with these ⟩
in JavaScript/jQuery?
The result should look like:
<b><a href="#">Home</a> ⟩ <a href="#">This Page</a></b>
I tried:
$('b').text($(this).text().replace('>','⟩'));
But it almost made my browser crash...
Thanks in advance.
Upvotes: 0
Views: 1122
Reputation: 15709
Try:
var t = $("b").html();
$("b").html(t.replace(/>/g,"}"));
Upvotes: 0
Reputation: 171689
Will have to isolate text nodes
In example <b>
tag:
var content=$('b').contents();
content.each(function(){
if( this.nodeType===3){/* text node*/
this.textContent=this.textContent.replace(/>/g,'}')
}
});
Upvotes: 2