setStyle() throwing errors in IE when object does not exist

Kickboy wrote:
> I'm trying to set the style of elements that are created through
> document.createElement() using the setStyle() function. Looks
> something like this:
>
> var newdiv = document.createElement('div');
> newdiv.setStyle({
>   position: 'relative',
>   width: '100px'
>   ...
> });

Try this:

var newdiv = Element.extend(document.createElement('div'));
newdiv.setStyle({
  position: 'relative',
  width: '100px'
  ...
});

 
IE doesn't automatically extend new elements based on their Javascript prototype
even though it should since that's what prototype programming means. But oh
well.

 

Yes, IE doesn't support native prototypes for DOM stuff - only for core
JavaScript stuff like Array, Object, Function etc.

 

转自:http://www.mail-archive.com/[email protected]/msg00764.html

你可能感兴趣的:(JavaScript,html,IE,prototype)