JavaScript - Add style using javascript. - Asked By RAJESH VEMUNOORI on 29-Mar-13 01:43 PM

Hi All,

I'm using below code to display a div dynamically for validation messages.

function DisplayError(lnk, msg) {
    var warningSpan = document.createElement("div"); = "red"; = "left";
    warningSpan.innerHTML = ''
    warningSpan.innerHTML = msg;
    document.getElementById(lnk).parentNode.insertBefore(warningSpan, document.getElementById(lnk).nextSibling);
    setTimeout(function () { warningSpan.innerHTML = ''; }, 2000);

In this scenario the style 'float' is not applicable to the created div even though i added as above. Please let me know if i'm wrong any where or is there any other way to apply style for float..

Appreciate your help.
Robbe Morris replied to RAJESH VEMUNOORI on 29-Mar-13 04:37 PM
This is much easier to do with css class names.

 warningSpan.className = 'some css classname';
RAJESH VEMUNOORI replied to Robbe Morris on 30-Mar-13 02:17 AM
Thats a good idea Robbe..