1

How can I create <div horizontal layout></div> element dynamically using javascript?

i can create div element with document.createElement("div"); but how do I add horizontal layout to it?

TechnoA
  • 65
  • 7

1 Answers1

3
<html>
<head>

<script type="text/javascript">
window.onload = function() {

newdiv = document.createElement("div");
newdiv.setAttribute('horizontal', '');
newdiv.setAttribute('layout', '');
document.body.appendChild(newdiv);
// You can insertBefore() too.

// Or... document.body.innerHTML = document.body.innerHTML + '<div horizontal layout></div>';

}
</script>
</head>
<body>
</body>
</html>

Some helpful links:

http://www.w3schools.com/jsref/met_document_createelement.asp

Adding elements to the DOM

Searching elements in DOM

How to add or update an attribute to an HTML element using JavaScript?

And so on.

Community
  • 1
  • 1
rafaeldefazio
  • 439
  • 2
  • 7