javascripthtmlappendchildcreateelementcreatetextnode

Creating Elements no Scrolling


When I use document.createElement() and create a bunch of elements in js which transfer onto my page it does not go down vertically. Once it reaches the end of the page the elements start of pile horizontally. Does anyone know how to stop this from happening?

In the photo below, you can see the text checkboxes and radios piling up and then the upload button on the side instead of further down. enter image description here


Solution

  • Your upload button is an inline element, which does not start from a new line.

    There are several type of elements, such as inline and block. Inline elements continue from the same line where as block elements span the entire width of the page and start from a new line. The upload button getting stacked on the side is not due to you JavaScript, but because it is an inline element.

    You can add <button style="display:block">Upload</button> to make it a block level element.

    See https://www.w3schools.com/cssref/pr_class_display.asp