function createDiv(nameId,width,height,color)
{
    try
    {
        // Initialize And Create Div
        if(document.createElement('div'))
        {
            // document.write("<br>Create Div Success");
            if((nameId.length!=0) && (width>0) &&(height>0) && (color.length!=0))
            {
                //creating div
                var divCreate = document.createElement('div');
                divCreate.id=nameId;
                document.getElementById(nameId).width = width;
                document.getElementById(nameId).height = height;
                document.getElementById(nameId).background = color;
                document.getElementById(nameId).backgroundColor = "Red";
                document.body.appendChild(divCreate);
                document.write(" <br>Create Div Success And Added To Body");
                // document.write(" <br>Create Div Success And Added To Body");
            }
            else
            {
                //     document.write("<br>All Field Value Required");
            }
        }
        else
        {
            document.write("<br>Unable To Create Div");
        }
    }
    catch(e)
    {
        document.write("<br>"+e);
    }
}
document.getElementById() is getting Null. I am trying to create a DIV using javascript and assigning some width/height and color to it, but its not working. However, if I use the code below the div gets created but it's not visible on the screen. And if I use the function createDiv() it does not work.
divCreate.id=nameId;
divCreate.width = width;
divCreate.height = height;
divCreate.background = color;
divCreate.backgroundColor = "Red";
document.body.appendChild(divCreate);
 
     
     
     
    