New jquery (later than 1.6) needs to use prop() instead of attr().