Document.write output won't stay inside div

I want to use document.write to output the values of an array. If the array is too long, it totally ignores the width of the container div. How do I get the values to word-wrap when they get to the end of the container?

I’ve searched on this forum, and also googled for the answer but can’t find a solution. I’m still fairly new to Javascript.

Thanks. That makes a lot of sense, but of course it didn’t occur to me. I guess that will come with more experience. As you advised, I used the join() method with my array to get the spaces between, but right now something is going wrong, and I can’t get it to work. I am going to debug it later when I get some time.

No, I am playing around with multiples of a number between two values, and if there are too many elements in the array, they don’t wrap … they just keep on going on the same line. I thought it might have something to do with overflow, so I tried overflow: none and it didn’t work.

I tried overflow: auto, and it just cut off my display when it got to the edge of the container.

That would be done using CSS, especially ‘overflow’:

You would need to apply the correct overflow rule (overflow: auto) to the div you’re writing your array to.

Sorry, didn’t read properly.

“the array is too long” - do you mean the value is wider than the div?

You’ll need to have a white-space character between the array elements in your output, or browsers won’t wrap the line. They’re not allowed to.

The value none is not valid for the overflow property. You can use visible (default), hidden (not very useful in this case), scroll or auto. But the latter two will just give you a horizontal scroll bar. It’s much better to output spaces between the array elements so that the browser can wrap the lines.