I have an HTML page like this
<div id="div"></div>
I want do add there two elements (the problem appears with a
and button
) using JavaScript
a1 = document.createElement("a")
a1.innerText = "element1"
div.appendChild(a1)
a2 = document.createElement("a")
a2.innerText = "element2"
div.appendChild(a2)
The result is <div id="div"><a>element1</a><a>element2</a></div>
.
It differs from
<div id="div">
<a>element1</a>
<a>element2</a>
</div>
The second variant has some space beetween words.
Why does this happen? What should I do in order to get some fixed amount of space (I need it because originally worked with buttons)? What is the proper actions in this situation?