topical media & game development
#javascript-code-24-createelement.js / js
// Create a new <strong> element
var s = document.createElement(“strong”);
// Find the first paragraph
var p = document.getElementsByTagName(“p”)[0];
// Wrap the contents of the <p> in the <strong> element
while ( p.firstChild ) {
s.appendChild( p.firstChild );
}
// Put the <strong> element (containing the old <p> contents)
// back into the <p> element
p.appendChild( s );
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.