2

I'm trying to append a string to a HTML element. It works fine when it's a one line string, but when I try to break it apart it stops working.

  <div><h4 >List to do:</h4><span id="added"></span></div>

This doesn't work:

  var addtext = "<ol>
                 <li>Item1</li>
                 <li>Item2</li>
                 </ol>"


                 $("span#added").html(addtext);

Can anyone help to make it work. I want to add a lot of HTML code, and I'd like it to be readable?

2 Answers 2

10

try this :

var addtext = "<ol>\
                 <li>Item1</li>\
                 <li>Item2</li>\
                 </ol>";
Sign up to request clarification or add additional context in comments.

1 Comment

Yes it works now. Thank you. So I need to escape a <CR>? Didn't know that.
-2
var addtext = '<ol><li>Item1</li><li>Item2</li></ol>';

1 Comment

It is not multiline string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.