Prototype (1.6.0.3) function .insert does not work within dom:loaded event in Magento 1.4
I have a strange problem regarding prototype's insert function during a dom:loaded event. Every time i use [element].insert() script execution stops for the event. I use the following code:
document.observe("dom:loaded", function() {
$$('.some-class').insert({top: new Element('div').addClassName('top')}).insert({bottom: new Element('div').addClassName('bottom')});
alert('This message never shows...');
});
However, if I simply change insert to invoke('hide'), all is well:
document.ob开发者_如何学Cserve("dom:loaded", function() {
$$('.some-class').invoke('hide');
alert('This message shows...');
});
Does anybody know how I can get .insert working? I simply can't find a way to do this. Perhaps this has something to do with Magento as well?
Duh!
It's so simple if you know what you are doing!
The code should be changed to the following:
document.observe("dom:loaded", function() {
$$('.some-class').each(function(e) {
e.insert({top: new Element('div').addClassName('top')}).insert({bottom: new Element('div').addClassName('bottom')});
});
});
That actually makes sense. I'm happy now :)
精彩评论