Add Inline Style Using Javascript
I'm attempting to add this code to a dynamically created div element style = 'width:330px;float:left;' The code in which creates the dynamic div is var nFilter = document.create
Solution 1:
nFilter.style.width = '330px';
nFilter.style.float = 'left';
This should add an inline style to the element.
Solution 2:
You can do it directly on the style:
var nFilter = document.createElement('div');
nFilter.className = 'well';
nFilter.innerHTML = '<label>'+sSearchStr+'</label>';
// Css styling
nFilter.style.width = "330px";
nFilter.style.float = "left";
// or
nFilter.setAttribute("style", "width:330px;float:left;");
Solution 3:
Using jQuery :
$(nFilter).attr("style","whatever");
Otherwise :
nFilter.setAttribute("style", "whatever");
should work
Solution 4:
You can try with this
nFilter.style.cssText = 'width:330px;float:left;';
That should do it for you.
Solution 5:
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);
Post a Comment for "Add Inline Style Using Javascript"