Reputation: 295
Hi I am trying to change the contents of a hidden input.
var temp = $("#header").val().replace("(/<\/div><div>/g","<br>");
I tried using the following replace but it does not change it.
May I know what I did wrong? I am trying to replace:
</div><div>
to
<br>
EDIT - this is my program flow
User enters input to a wysiwyg text editor which produces the output
Save the user input to database
Go to another page where the wysiwyg input is retrieved from database and save it to input type hidden
Replace the </div><div>
to a <br>
which is then outputted to a div
Upvotes: 0
Views: 2340
Reputation: 856
To replace all ocurrences in a string, the correct syntax with regExp is:
var temp = $("#header").val().replace(/<\/div><div>/g,"<br>");
You can test it, here:
'</div><div></div><div></div><div></div><div>'.replace(/<\/div><div>/g,"<br>");
returns:
<br><br><br><br>
Upvotes: 1
Reputation: 6753
You should do:
.replace(/<\/div><div>/g,"<br>");
The RegExp should not be enclosed within quotes else it would be a String. Also, the .val()
method is used for textareas. Use .html()
for header
, div
s, etc.
Upvotes: 0