My goal is to display input field and span right next to it. To achieve this I generate two divs inside a parent one (two "small-6 columns" inside "row" from foundation framework).
If I go for .appendChild(el) and .appendChild(span) it works. When I want to put the divs in work I get [object HTMLDivElement][object HTMLDivElement] printed as result.
I have tried $(ldiv).html() and many variations, but I just cant figure it out.
Thank you for response
var cellRight = row.insertCell(1);
var div = document.createElement('div');
div.class = 'row';
//
var el = document.createElement('input');
el.type = 'text';
el.name = 'produkty_mnozstvi_jednotek' + iteration;
el.id = 'produkty_mnozstvi_jednotek' + iteration;
el.style.width = '3.5rem';
//
var ldiv = document.createElement('div');
ldiv.class = 'small-6 columns';
ldiv.id = 'ldiv' + iteration;
ldiv.innerHTML = el;
//
var span = document.createElement('span');
span.id = 'naskladneni_mnozstvi_jednotek' + iteration;
//
var rdiv = document.createElement('div');
rdiv.class = 'small-6 columns';
rdiv.id = 'rdiv' + iteration;
rdiv.innerHTML = span;
//
div.innerHTML = div.innerHTML + ldiv + rdiv;
//
cellRight.appendChild(div);
//cellRight.appendChild(el);
//cellRight.appendChild(span); //works fine but divs are ignored and span in under the input, not next to it (workaround)
Use appendChild instead of innerHTML. Maybe it helps you:
function run() {
var row = document.getElementById('row');
var cellRight = row.insertCell();
var div = document.createElement('div');
div.class = 'row';
var el = document.createElement('input');
el.type = 'text';
el.name = 'produkty_mnozstvi_jednotek' + iteration;
el.id = 'produkty_mnozstvi_jednotek' + iteration;
el.style.width = '3.5rem';
//
var el = document.createElement('input');
el.type = 'text';
el.name = 'produkty_mnozstvi_jednotek' + iteration;
el.id = 'produkty_mnozstvi_jednotek' + iteration;
el.style.width = '3.5rem';
//
var ldiv = document.createElement('div');
ldiv.class = 'small-6 columns';
ldiv.id = 'ldiv' + iteration;
ldiv.appendChild(el);
//
var span = document.createElement('span');
span.id = 'naskladneni_mnozstvi_jednotek' + iteration;
//
var rdiv = document.createElement('div');
rdiv.class = 'small-6 columns';
rdiv.id = 'rdiv' + iteration;
rdiv.appendChild(span);
//
div.appendChild(ldiv);
div.appendChild(rdiv);
cellRight.appendChild(div);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With