Hi, > IE doesn't know document.body
It does, but it's not an extended element[1] by default, you have to extend it via $()[2]. This should work: $(document.body).insert(a); [1] http://www.prototypejs.org/learn/extensions [2] http://www.prototypejs.org/api/utility/dollar HTH, -- T.J. Crowder tj / crowder software / com On Nov 21, 10:58 pm, chrissu13 <[EMAIL PROTECTED]> wrote: > Hi, one additional question: > > -> document.body.insert(a); > In FF the code works - IE doesn't know document.body. Is there any > common alternative or do I have to code different browser versions > even in prototype? > > Cheers, > Chrissu > > On 21 Nov., 23:10, Matt Foster <[EMAIL PROTECTED]> wrote: > > > > > What do I make wrong > > > Many things... > > > > > <script> > > > > var a = new Element('div', {id: 'my_div'}); > > > > $('my_div').style.witdh = '200px'; > > > > </script> > > > > </head> > > > -You create an element, but never attach it to the DOM. > > -Even if you did attach it, the DOM wouldn't be ready at that point in > > execution, you've got your script running in the head element. There > > are many ways to execute code after the DOM has finished loading, in > > my opinion, the easiest is simply placing the script tag at the bottom > > of the <body> element. > > -Why not just use the direct reference to the object, you just created > > it, why would you ask the DOM for a reference? > > a.style.width = "200px"; > > > On Nov 21, 4:35 pm, "Hector Virgen" <[EMAIL PROTECTED]> wrote: > > > > When you create an element with "new Element()", it only exists as a > > > javascript variable until you append the element to the DOM. > > > > The $() function looks in the DOM for the element, which is why it is not > > > finding it. > > > > Also, you may want to use Element#setStyle() instead of accessing the > > > style > > > property directly. It's much more consistent cross-browser. > > > > var a = new Element('div', {id: 'my_div'}); > > > a.setStyle({width: '200px'}); > > > > -Hector > > > > On Fri, Nov 21, 2008 at 11:35 AM, chrissu13 <[EMAIL PROTECTED]> wrote: > > > > > What do I make wrong that Firebug gives me a "$("my_div") is null" > > > > Error-Message when debugging the following lines? > > > > > Chrissu > > > > > ------ > > > > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:// > > > >www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> > > > > <html xmlns="http://www.w3.org/1999/xhtml"> > > > > <head> > > > > <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> > > > > <script type="text/javascript" src="LIB/prototype.js"></script> > > > > <title>test</title> > > > > <script> > > > > var a = new Element('div', {id: 'my_div'}); > > > > $('my_div').style.witdh = '200px'; > > > > </script> > > > > </head> > > > > <body> > > > > </body> > > > > </html> > > > > --------- > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~----------~----~----~----~------~----~------~--~---