How Can I Convert Object Htmlbuttonelement to Html Button?

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?

8

2 Answers

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>
0

Instead of element use element.HTML ....such properties like .HTML , .value , .Text will not return object htmlbuttonelement .

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Elena Rostova

Elena Rostova

Lead Health, Wellness & Medical Journalist

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.

Share this article
Twitter Facebook Pinterest