Replace the hyphen with space for the text specified in the div

<div>This-is-text-1</div> 

Given a line of code

 var value = $('div').text(); 

I need to redo hyphens into empty space . I need a conclusion: "This is text 1". How can I use jQuery replace function here?

+4
source share
4 answers

Try

 var value = $('div').text(); $('div').text(value.replace(/\-/g, " ")); 

Demo: Fiddle

+4
source

try it

 $('div').text($('div').text().replace(/-/g, ""); 
0
source

Try it -

 $('div').html().replace("-"," "); 
0
source

use regex to replace all occurrences - :

 var value = $('div').text(); $('div').html(value.replace(/-/g, " ")); //--------------------------^---^-----g is used to replace all occurrences and //------------------------------------" " put a space too to replace with 

Fiddle

0
source

All Articles