admin管理员组文章数量:1201171
I have some auto-generated text that includes non-ascii encoded parentheses. For example:
<div> Some text (these are the non-ascii encoded parenthesis).
<div>
I want to get rid of the parenthesis. I have the following, which I use elsewhere to clean out some html elements, but I can't get similar to work to remove actual text:
jQuery(document).ready(function(){jQuery(".block").find("p").remove()});
I've found a few ideas around, but they deal with normal text. Getting rid of a parenthesis is a challenge, as I'm not sure how to code the parenthesis so that jQuery understands it.
Any ideas?
I have some auto-generated text that includes non-ascii encoded parentheses. For example:
<div> Some text (these are the non-ascii encoded parenthesis).
<div>
I want to get rid of the parenthesis. I have the following, which I use elsewhere to clean out some html elements, but I can't get similar to work to remove actual text:
jQuery(document).ready(function(){jQuery(".block").find("p").remove()});
I've found a few ideas around, but they deal with normal text. Getting rid of a parenthesis is a challenge, as I'm not sure how to code the parenthesis so that jQuery understands it.
Any ideas?
Share Improve this question edited Aug 25, 2011 at 11:38 jAndy 236k57 gold badges311 silver badges363 bronze badges asked Aug 25, 2011 at 11:34 user624385user624385 3731 gold badge6 silver badges14 bronze badges 2- Do you want to get rid of the parentheses themselves, or everything they contain as well? – James Allardice Commented Aug 25, 2011 at 11:36
- I'm just looking to ditch the parentheses, but it looks like Andy's answer below includes code to nix everything in between also. Thanks for replying. – user624385 Commented Aug 26, 2011 at 10:05
1 Answer
Reset to default 25You should do the replacing/cleaning with vanilla Javascript. Something like
$('div').text(function(_, text) {
return text.replace(/\(|\)/g, '');
});
will do it. Notice, this would query for all <div>
nodes on the entire side, you want to be more specific on the selector.
demo: http://jsfiddle.net/2gHh2/
If you'd like to remove the parenthesis and everything in between, you'd simply have to change the regular expression to /\(.*?\)/g
.
本文标签: javascriptHow Do I Remove a text Parenthesis Using JQueryStack Overflow
版权声明:本文标题:javascript - How Do I Remove a text Parenthesis Using JQuery? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738628328a2103594.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论