Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.createElement('div'); nFilter.className = 'well'; nFilter.innerHTML = '<label>' + sSearchStr + '</label>'; 

My idea is to add the style after < div class="well" but i don't know how i'd do it.

like image 744
Curtis Crewe Avatar asked Feb 07 '13 14:02

Curtis Crewe


People also ask

What is inline style in JavaScript?

Inline styles are applied directly to the specific HTML element using the style attribute. In JavaScript the style property is used to get or set the inline style of an element. The following example will set the color and font properties of an element with id="intro" .

How do you create an inline style?

Inline - by using the style attribute inside HTML elements. Internal - by using a <style> element in the <head> section. External - by using a <link> element to link to an external CSS file.

How do I get inline CSS?

If you want all of the inline-styles as text, either get the style attribute (as you're doing) or use this. style. cssText .


1 Answers

nFilter.style.width = '330px'; nFilter.style.float = 'left'; 

This should add an inline style to the element.

like image 70
Dharman Avatar answered Oct 02 '22 18:10

Dharman