He doesn't actually use 'documet.write'; he changes it into something else.
Namely, innerHTML — not much better, really.
Nice point Twey... I think that was just a "I wanna be lazy" tangent honestly.
I actually almost have the script how I'd like it by using the DOM method thanx to people who helped in my last post.
Code:
<script type="text/javascript">
function initload(value){
if (document.getElementById("bojo").firstChild == null) {;}
else
{document.getElementById("bojo").removeChild(elOpt);}
elOpt = document.createElement(value);
elOpt.setAttribute("id","my" + value);
elOpt.style.border = "4px solid #cccccc";
elOpt.style.height = "40px";
elOpt.style.width = "40px";
elOpt.onmouseout = function() {initload('div');};
elOpt.onmouseover = function() {initload('textarea');};
document.getElementById("bojo").appendChild(elOpt);
}
</script>
<body id="body" onload="initload('div');">
<div id="bojo" name="bojo" ></div>
</body>
Laziness is the mother of invention
You've just gone about it the wrong way in this case. You shouldn't have to write out the calls by hand, but there are better ways than presenting it as a string. See for example this post; using that function, it could be written:
Code:
function initload(value) {
var bojo = Dom.get("bojo");
Dom.clear(bojo);
bojo.appendChild(Dom.create(
[value,
{
id: "my" + value,
onmouseout: function() { initload('div'); },
onmouseover: function() { initload('textarea'); }
style: {
border: "4px solid #cccccc",
height: "40px",
width: "40px"
}
}
]);
}
Simple, easy, readable, no big strings.
Bookmarks