首页 > 解决方案 > Is it possible to add a div to an element horizontally using javascript?

问题描述

I'm adding elements to a form in javscript using appendChild, and am wondering if there is a way to append horizontally instead of vertically? Using appendChild(), I tried this:

var select_fields = document.createElement('select');
select_fields.setAttribute('id', 'select_fields');
var select_operators = document.createElement('select');
select_operators.setAttribute('id', 'select_operators');
select_operators.setAttribute('display', 'inline')             

var filter_field_header = document.createTextNode('Choose Field:');
filter.appendChild(filter_field_header);
filter.appendChild(select_fields);
filter.appendChild(select_operators);

But it still appends vertically. Is this possible?

标签: javascriptappendchild

解决方案


尝试使用 'float: left' 而不是使用 'display: inline'


推荐阅读