wrote:
> I need to put all body content into wrapper when page is loaded. Via
> javascript of course.
>
> Initial DOM
>
> <body>
> <div>
> <p>Some text</p>
> <p>More text</p>
> </div>
> </body>
Actually, that is not a DOM (Document Object Mode) which is an API
(Application Programming Interface). It is a document fragment.
> Modified DOM with javascript
>
>
> <body>
> <div id="myWrapper">
> <div>
> <p>Some text</p>
> <p>More text</p>
> </div>
> <div>
> </body>
>
> Any idea?
While some people would advocate innerHTML parsing and even worse methods,
it is important to keep in mind that objects have identity in the language
as they have in the document tree. Therefore, Node::appendChild() is
explicitly specified to move a node if it is appended in a different location:
var oldDiv = document.getElementsByTagName("div")[0];
var divWrapper = document.createElement("div");
divWrapper.id = "myWrapper";
divWrapper.appendChild(oldDiv);
document.body.appendChild(divWrapper);
You should add the usual feature tests and associated fallbacks, of course.
HTH
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16