Hello,
I am using javascript DOM elements like document.createElement('div'), document.createTextNode('text') for creating html elements & text elements. I want to append linebreak between the elements. I tried like document.createElement('br'). But that didn't worked. How can I append space between elements using javascript DOM? Please help me. Thanks in advance.
[RESOLVED] Adding linebreak using javascript DOM
What do you mean "a linebreak between elements"?
actually i want to add a <br> between html elements like textbox ,combo etc....
So, you created the <br> element; did you insert it anywhere?
yes, i tried to insert br using javascript something like this,
obj.createElement('br') . But that didn't worked...
That creates an element (hence the name, "createElement"), it doesn't insert it (as, say, "insertBefore" or "appendChild" would).
solved... i have used
document.createTextNode('\u00A0')
and it has created blank space....
Oh, so you don't want a <br> element.
no i wanted <br> element only... and it has created <br> using this code....
Just responding because I found this post via Google and wanted to clarify the solution. I apologize for necro-posting.
The solution specified will add a single space which, depending upon content length and various other things, may or may not create a line break.
The original issue was that the OP was attempting to call the createElement method on the node object, while this method only exists in the document object.
The correct way to do this would be:
var br = document.createElement('br');
obj.appendChild(br);
This code adds a line break at the bottom of the obj object.
Just wanted to clarify that in case someone came across this like I did.