Postion an element with javascript


#1
var hiddenText = document.createElement("TEXTAREA");
document.body.appendChild(hiddenText);
hiddenText.setAttribute("id", "hiddenText");

how do i use plain javascript to position this textarea off the page so that is unseen?

if i have to create a css style, how do i use javascript to write the css into the head?


#2

Can you add CSS styles to the page directly via a style tag? Or are you looking for a pure JS only solution?

For a JS-only solution, you can do this:

hiddenText.style.position = "absolute";
hiddenText.style.left = -9999px;

:slight_smile: