开发者

How to replace "(" and ")" with "<span>" and "</span>" jQuery

I have follow h开发者_高级运维tml code:

<a href="#">Evente (0)</a>

an i need:

<a href="#">Evente <span>0</span></a>

how i can change it with jQuery?


I think you should use standard JS regexp:

str.replace(/\(/g, '<span>').replace(/\)/, '</span>')


Probably following is cleaner in regards of jQuery functionallity:

$('a').html(function(i,html){ return html.replace(/\((.*?)\)/, "<span>$1</span>")})


Don't use jQuery.

myAtag.innerHTML = myAtag.innerHTML.replace(/\(/,'<span>').replace(/\)/,'</span>');

Better still, output it from the server like that in the first place.


My thought for using jquery;

I added an ID to the achor tag to make it simpler to reference:

<a id='target' href="#">Evente (0)</a>

And the following JQuery code

$('#target').html($('#target').html().replace("(","<span>").replace(")","</span"));

Similar to both of the above answers, but with JQuery


Thank you SHiNKiROU now is running goooood ;)

$("#content-tabs a").text().replace(/\(/g, '<span>').replace(/\)/g, '</span>');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜