Help! My mootools script doesn't work in IE!
Today I went through the pain of installing Windows XP. On QEMU. I wanted to do some JavaScript debugging for mootools. It turned out that IE was just a little picky about list formatting.
Whenever you list things, IE scripting breaks if you add a comma behind the last element. It's probably incorrect to add a comma and the examples at docs.mootools.net are all correct. But it surprised me nonetheless as IE lets terribly broken HTML pass and other browsers are more forgiving. Anyway, fixing sloppy code is always a good thing.
This won't work in the Internet Explorer I tested:
window.addEvent('domready', function() {
var elements = $('sidebar').getElements('a');
elements.each(function(item, index) {
var elem = $(item);
elem.addEvents({
'mouseenter': function() {
elem.setStyle('background-color', '#ccf');
},
'mouseleave': function() {
var myFx = new Fx.Tween(elem, {
duration: 250,
link: 'ignore',
transition: 'sine:out',
});
myFx.start('background-color', '#ccf', '#eef');
},
});
});
});
(Errors on lines 13 and 16)This will work:
window.addEvent('domready', function() {
var elements = $('sidebar').getElements('a');
elements.each(function(item, index) {
var elem = $(item);
elem.addEvents({
'mouseenter': function() {
elem.setStyle('background-color', '#ccf');
},
'mouseleave': function() {
var myFx = new Fx.Tween(elem, {
duration: 250,
link: 'ignore',
transition: 'sine:out'
});
myFx.start('background-color', '#ccf', '#eef');
}
});
});
});
Some day I may read through the JavaScript specs and find out if this behaviour is to be expected. Another resource I haven't gone through yet is this excellent post at the mootools blog.
If you're interested in debugging JavaScript for IE you should read this How to debug JavaScript in IE as well.
I am Nicolas Kuttler, a web developer, system administrator and IT consultant from France, currently living in Germany.





2 comments
Start a new thread