简体   繁体   中英

get new line after input element javascript

I am dynamically adding input elements so user can input emails. I need each input element (which is inserted after a button) to be on a separate line. Here is the function:

function feMail()
{
var element = document.createElement("Input");
element.setAttribute("type", "text");
document.body.appendChild(element);
linebreak = document.createElement("br");
element.appendChild(linebreak);
}

I tried the linebreak above, but it is not working. Just a beginner coder here so thanks for any help.

You should append the linebreak to document.body , not element . The element you are creating looks like this:

<input type="text">
    <br>
</input>

The last line should instead be document.body.appendChild(linebreak); .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM