0

I am calling these variables which are question in a quiz (multiStr).

How can I insert a line break? I have tried \n and "+

If it's not possible, can I insert some HTML in the middle to break up the question to multiple lines?

var multiStr = [ { "question" : " Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec varius pharetra tellus.", "choices" : [ "True", "False", ], "correct" : "False", "explanation" : " Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec varius pharetra tellus, ac porta sem sollicitudin eget.", }, 
1
  • What function do you use to put the string on the screen? Commented Mar 4, 2014 at 8:54

2 Answers 2

1

/n is working fine for line breaks try both examples.

var a = "hello test \n the code "; console.log(a) var multiStr = [ { "question" : " Lorem ipsum dolor sit amet, \n consectetur adipiscing elit. Donec varius pharetra tellus.", "choices" : [ "True", "False", ], "correct" : "False", "explanation" : " Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec varius pharetra tellus, ac porta sem sollicitudin eget.", }]; alert(multiStr[0].question); 

In Html you can use <br/> for line breaks

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

Comments

0

use \n and instead of append method use .empty().html("you text"+"\n") or use <br>

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.