Skip to content

Instantly share code, notes, and snippets.

@benglewis
Last active August 29, 2015 14:05
Show Gist options
  • Save benglewis/13805ba270c5ef67e0e8 to your computer and use it in GitHub Desktop.
Save benglewis/13805ba270c5ef67e0e8 to your computer and use it in GitHub Desktop.
var newDiv = document.createElement("div");
var newContent = document.createTextNode("Hi there and greetings!");
newDiv.style.textAlign = "center";
newDiv.style.position = "absolute";
newDiv.style.height = "50px";
newDiv.style.width = "500px";
newDiv.style.top = "50%";
newDiv.style.left = "50%";
newDiv.style.marginTop = "-25px";
newDiv.style.marginLeft = "-250px";
newDiv.style.backgroundColor = "#aaa";
newDiv.style.border = "1px solid #777";
newDiv.style.zIndex = "100";
newDiv.appendChild(newContent); //add the text node to the newly created div.
var newButton = document.createElement("button");
newButton.innerHTML = "OK";
newButton.onclick = "function() { document.removeChild(newDiv); }";
newDiv.appendChild(newButton);
document.getElementsByTagName('html')[0].appendChild(newDiv);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment