|
Post by Schubaltz on Jun 10, 2007 15:38:22 GMT -5
Description: Creates an element and assigns it its properties.
Syntax: createElement(tagName, {,properties})
function createElement(a, b) { if(a.constructor == String) a = document.createElement(a); for(var x in b) { if(b[x].constructor == Object) { createElement(a[x], b[x]); continue; } a[x] = b[x]; } return a; }
Example:
<html> <head></head> <body> <script type="text/javascript"> <!-- var i = createElement("a", { href: "http://www.google.com/", style: { color: "#000099", backgroundColor: "#4444FF", padding: "5px" }, onclick: function() { if(!confirm("Leaving?")) return false; } }); i.appendChild(document.createTextNode("Google")); document.body.appendChild(i); //--> </script> </body> </html>
|
|