Reputation: 11
I have a ul with a lot of li each with a child, like that:
<ul>
<li><a href="#">Belts (2)</a></li>
<li><a href="#">Tenis (92)</a></li>
<li><a href="#">T-Shirts (368)</a></li>
</ul>
I need to remove the parentheses and the numbers inside, but let the rest, i.e:
<ul>
<li><a href="#">Belts</a></li>
<li><a href="#">Tenis</a></li>
<li><a href="#">T-Shirts</a></li>
</ul>
How to do it with jquery and regular expression? I have no idea! :(
Upvotes: 1
Views: 1526
Reputation: 145368
$("ul li a").html(function(i, html) {
return html.replace(/\(\d*\)/, "");
});
DEMO: http://jsfiddle.net/JVVvQ/
Upvotes: 3
Reputation: 219920
$('a').text(function (_, v) {
return v.replace(/ \(\d+\)$/, '');
});
Here's the fiddle: http://jsfiddle.net/63H2T/
Upvotes: 2