How to add an element to 'body' using Prototype?

Senthil picture Senthil · May 10, 2010 · Viewed 14.6k times · Source

I have created an element like this:

var myDiv = new Element('div');
myDiv.update('Hello!');

I want to add myDiv to body.

I tried

$('body').insert(myDiv);

But it is not working. I also tried

$('body')[0].insert(myDiv);

thinking that $('body') was returning an array. Even that didn't work.

How can I add myDiv to body?

Thanks.

Answer

Pekka picture Pekka · May 10, 2010

How about

$(document.body).insert(myDiv);

?

Differently from jQuery, in Prototype, $('body') fetches the element with the id body.