Whirlwind991 Whirlwind991 - 2 years ago 104
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");

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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download