How do I put a break in JavaScript? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

How do I put a break in JavaScript?

I have a <input> in html and a document.getelementbyid() in JavaScript, and I can't figure out how to put a <br> in the document.getelementbyid() so it will show up in the <input> https://code.sololearn.com/Wl3R6L8nHXPy/?ref=app

23rd Mar 2018, 4:22 PM
Punderful20 Quack
Punderful20 Quack - avatar
4 Answers
+ 5
@Punderful20 Quack, Apparently the only option to have multiple lines input was by using textarea, and indeed "\n" will turn into a line break in textarea. One more thing is that you named your function with a keyword (break), I recommend you to change the function name, and use textarea instead of input. https://stackoverflow.com/questions/6262472/multiple-lines-of-input-in-input-type-text
27th Mar 2018, 3:31 AM
Ipang
+ 7
Can you link your code with the question? it will help others to understand the question if they can see your code : )
23rd Mar 2018, 4:34 PM
Ipang
+ 4
You could do something like: var el = document.getElementById("myElement"); var br = document.createElement("br"); el.appendChild(break); ^Maybe that's what you're asking? Honestly, I'm having trouble understanding exactly what you're asking. What exactly are you trying to do? You want to print <br> inside of the box but not break a line? You're wanting to add a <br> after the input? Try to explain it a bit further and I'll be happy to help.
23rd Mar 2018, 4:38 PM
Fata1 Err0r
Fata1 Err0r - avatar
+ 3
I tried some random stuff and the answer is "\n"
27th Mar 2018, 2:56 AM
Punderful20 Quack
Punderful20 Quack - avatar