0

I know this a repeat question, but I tried a lot of things and none of them worked. Essentially, I have:

var med = word.replace("!", '<br />'); (div.get(0)).textContent = med; 

Side note: the div has a <p> inside of it and that is what I am changing. Thank you for any advice in advance!

3
  • 2
    maybe a jsfiddle link could be useful. Commented Nov 5, 2016 at 3:46
  • And the problem is? Commented Nov 5, 2016 at 3:50
  • It wont insert a line break, like I think it should. Commented Nov 5, 2016 at 3:51

2 Answers 2

2

I can't see the whole of your code so I'm not sure what your HTML looks like. Try this code:

var str = jQuery('p').html(); str = str.replace('!', '<br />'); jQuery('p').html(str); 

There is a jsFiddle here: https://jsfiddle.net/pavkr/bq8be893/

You could simplify the code but this is basically just to show you how it works.

Sign up to request clarification or add additional context in comments.

Comments

1

You have to insert the content as html rather than as text. Do it like this:

var med = word.replace("!", '<br />'); (div.get(0)).innerHtml = med; 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.