0

I have appended a textbox to a div area. However I want it to goto a new line in that div after it does that, so my for loop prints a column of textboxes instead of a row.

I tried this:

<div id="timearea"> </div>
var br = '<br/>';
br.appendTo("#timearea");

However this does not work. What would the code be?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
giedrere
  • 81
  • 5

3 Answers3

4

You would need to create the element using the createElement() method then append the child to the element using the appendChild() method

var br = document.createElement("br");
document.getElementById("timearea").appendChild(br);
John Hartsock
  • 85,422
  • 23
  • 131
  • 146
0

I suggest you apply CSS styling to your divs to control how they are laid out. You can add attributes to style inline or (preferably) add classes to assign styles via JavaScript.

The display attribute controls the flow - display:block should do it.

.my_block_class {
  display:block;
}

You can then add the class with JavaScript like so:

document.getElementById("timearea").className += "my_block_class";

Or, if you want to do it without classes:

document.getElementById("timearea").style.display = "block";
Community
  • 1
  • 1
brabster
  • 42,504
  • 27
  • 146
  • 186
0

Not sure if you mean textarea or input type="text" but regardless, it is better to do this in CSS. In your CSS file or inline style description add:

#timearea input {
  display:block;
}

If it's an input element you are adding, or:

#timearea textarea {
  display:block;
}

If it's a textarea.

Nathan Loyer
  • 1,339
  • 10
  • 20