views:

866

answers:

2

Dan Webb's Low Pro UJS extension to Prototype offers the following elegant DOM Builder:

var listItem = $li({ id : 'item-1' }, 
                 $strong("Some text")
               ); 
// returns a node equivalent to: <li id="item-1"><strong>Some text</strong></li>

$('a_list').appendChild(listItem);

While this works like a dream for us in Firefox and Safari, it explodes with delight in IE 6 and IE7 with the error "Object doesn't support this property or method"

Any insight into what Dan Webb's DOM Builder might be doing to wrap Element.new that isn't compatible with IE?

A: 

Since v1.6, Prototype has a had a built-in element constructor. The syntax is just a little different than Low Pro.

$('a_list').insert(new Element("li", {id: 'item-1'})).update('some text').wrap('strong')
Diodeus
True, thanks. Unfortunately much more cumbersome than Low Pro's syntax. Appears that you can chain constructors, but it's not clear how you would create more than one nested element at the same level.
Abie
Ok, ironed out the syntax for nesting siblings, but boy is it ugly compared to Low Pro.
Abie
Let's have a look.
Diodeus
+1  A: 

I would imagine the "Object doesn't support this property or method" error is coming from a call to one of Prototype's extended element methods (which are not applied automatically in IE). However, all the elements you're dealing with are coming from LowPro or the $() function, which should extend the elements for you.

You could try this and see if it resolves the problem:

var listItem = Element.extend($li({id: 'item-1'}, 
    Element.extend($strong("Some text"))
));

$('a_list').appendChild(listItem);

If that fixes it then LowPro isn't extending the elements, which is very odd. If it doesn't then there must be something else wrong, can you post a demo page somewhere?

Jack Sleight