Whirlwind991 Whirlwind991 - 3 months ago 14
Javascript Question

Adding style to a div created in javascript

Quick question, I've got a div being created in javascript:

var chartDiv = document.createElement("div");
this.viewElement.appendChild(chartDiv);


But I want to set a border style around this div after its created. Whats the best way to do this in the javascript?
Thanks

Answer

Use the element style object.

chartDiv.style.border = "thin solid #FFF";

Alternatively, just add a css class to your element that contains the styling you want.