How to remove Parenthesis text using jQuery?

I have auto-generated text that contains brackets not related to ascii. For instance:

<div> Some text (these are the non-ascii encoded parenthesis). <div> 

I want to get rid of parentheses. I have the following, which I use elsewhere to clear some html elements, but I can't get close to working to remove the actual text:

  jQuery(document).ready(function(){jQuery(".block").find("p").remove()}); 

I found some ideas, but they relate to plain text. Getting rid of the parenthesis is a problem since I'm not sure how to encode the parentheses so that jQuery understands it.

Any ideas?

+6
source share
1 answer

You have to do a replacement / cleanup with vanilla Javascript. Sort of

 $('div').text(function(_, text) { return text.replace(/\(|\)/g, ''); }); 

will do it. Note that this would request all the <div> nodes on the entire side, you want to be more specific in the selector.

demo: http://jsfiddle.net/2gHh2/

If you want to remove the brackets and everything in between, you just need to change the regular expression to /\(.*?\)/g .

+19
source

Source: https://habr.com/ru/post/895861/


All Articles