<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?
Try
var value = $('div').text(); $('div').text(value.replace(/\-/g, " "));
Demo: Fiddle
try it
$('div').text($('div').text().replace(/-/g, "");
Try it -
$('div').html().replace("-"," ");
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