Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
66
rated 0 times [  73] [ 7]  / answers: 1 / hits: 16464  / 8 Years ago, tue, april 12, 2016, 12:00:00

Hi I get object HTMLButtonElement
due to var btn = document.createElement('button'); this is normal behaviour
but how can I get normal button as an graphic instead of object?
i.e <button type=button>



like a converting object into a string but in this case
object to what?


More From » html

 Answers
3

In the dom, Button is stored as instances of HTMLButtonElement object, that is why when you try to convert it to string(calling toString()) you are getting [object HTMLButtonElement].



Since you want to add the button to the view(dom tree), you can just append the button instance to the tree using appendChild() like





var btn = document.createElement('button');
btn.innerText = 'this button';
document.getElementById('container').appendChild(btn);
document.getElementById('markup').innerText = btn.outerHTML;

<div id=container></div>
<pre id=markup></pre>




[#62603] Sunday, April 10, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
masonm

Total Points: 167
Total Questions: 87
Total Answers: 103

Location: Rwanda
Member since Wed, Jun 8, 2022
2 Years ago
masonm questions
;