Hide text between braces in javascript

0

How can I hide text that is enclosed in braces in my div

Ex:

<div> Hello {World} </div>
    
asked by anonymous 25.06.2018 / 21:25

3 answers

1

Using Regular Expression

var text = $("div").text();
$("div").html('').append(text.replace(/(\s\{.*?\})/, ''))
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div> Hello {World} </div>
    
25.06.2018 / 21:45
1

Hello, try this regular expression:

let getDiv = document.querySelector('.teste').innerHTML;

let newTeste = getDiv.replace(/(\s\{.*?\})/, '');

document.querySelector('.teste').innerHTML = newTeste;
<div class="teste">Hello {World} !</div>
    
25.06.2018 / 21:37
0

Take the div text, make a replace using regular expression

var textoDaDiv = $("div").text();  

$("div").text(textoDaDiv.replace(/ *\{[^)]*\} */g, ""));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div> Hello {World} </div>
    
26.06.2018 / 00:03