I append an input
field into a div
. What I want is a single space after the input field.
This is what I have tried:
const el = document.createElement('input');
el.setAttribute('type', 'number');
el.appendChild(document.createTextNode(' '));
/*
Also tried it with:
el.appendChild(document.createTextNode('\u00A0'));
el.appendChild(document.createTextNode(' '));
el.innerHTML = el.innerHTML ' ';
*/
const id = document.getElementById('content');
id.appendChild(el);
id.focus();
<div id="content" contentEditable="true"></div>
CodePudding user response:
You can use append
const id = document.getElementById('content');
const input = document.createElement('input');
const space = document.createTextNode('\u00A0')
input.setAttribute('type', 'number');
id.append(input, space);
id.focus();
<div id="content" contentEditable="true"></div>