In this website, if the letter entered is a new line, a new line would be returned, I have this like as follows
if (character === 'n'){
element = document.createElement('br');
I tried adding var
before, or even changing the single quotations to double, what is wrong with it?
Thank you in advance
2
Answers
Please add further information on what you are trying to do and provide a minimal reproducable example.
It looks like you don’t add the element to the body, so maybe try this:
This won’t add the element automatically on any keystroke. For that, you need to listen to the
keydown
event.You need to then append that element with
document.appendChild(element)
https://developer.mozilla.org/en-US/docs/Web/API/Node/appendChild
It looks like you’re doing this inside a loop, so either create the HTML string all as one (as in the below snippet) or add the element like so: