Skip to content Skip to sidebar Skip to footer

Js Forward Slash Not Printing

I want a javascript function to replace all the b's with an html tag but it's only printing . Here is the function: var destination = source.replace(/b/g,'&l

Solution 1:

Original

There is no reason for the \ in the string.

var destination = source.replace(/b/g,"<br/>");

jsFiddle Example

Edit

Now you gave a sample fiddle with this code

functiongettext(){
    var input = document.getElementById("input").value;
    var value = input.replace("/b/g","<br/>");
    var output = document.getElementById("out").value = value;
}

Look at the replace line

varvalue = input.replace("/b/g","<br/>");

it is a string not a regular expression

"/b/g"

It needs to be

var value = input.replace(/b/g,"<br/>");

jsFiddle Example with your code

Post a Comment for "Js Forward Slash Not Printing"