Add inline style using Javascript

前端 未结 11 1214
悲&欢浪女
悲&欢浪女 2020-11-28 06:10

I\'m attempting to add this code to a dynamically created div element

style = \"width:330px;float:left;\" 

The code in which creates the dy

11条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-28 06:27

    var div = document.createElement('div');
    div.setAttribute('style', 'width:330px; float:left');
    div.setAttribute('class', 'well');
    var label = document.createElement('label');
    label.innerHTML = 'YOUR TEXT HERE';
    div.appendChild(label);
    

提交回复
热议问题