I am trying to create div elements through Javascript, and add attributes to them through CSS.
There are two attributes:
- One for the background. This is working fine.
- One is for text. I am trying to add attributes to it in the say way I am adding attributes to the background, through id of the created
divelement. But due to some reason "TEXT" is not being displayed.
I have narrowed down the problem to diva.id="text";. But I am not sure what is wrong with it.
//grey block
var div=document.createElement('div');
div.id="overlay";
document.body.appendChild(div);
document.getElementById("overlay").style.display = "block";
//text
var diva=document.createElement('div');
diva.id="text";
var text= document.createTextNode('TEXT');
diva.appendChild(text);
document.body.appendChild(diva);
#overlay {
position: fixed;
display: none;
width: 100%;
height: 100%;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0,0,0,0.5);
z-index: 2;
cursor: pointer;
}
#text {
position: absolute;
color: white;
}