5 Answers
5

I think your double quotes around the onclick were making it not work. :)

EDIT: As pointed out below, inline javascript is evil and you should probably take this out of the onclick and move it to jQuery's click() event handler. That is how the cool kids are doing it nowadays.

+1 how could I possibly overlook this :)
–
Tamas CzinegeFeb 16 '09 at 14:10

18

You shouldn't use JavaScript inline, because it makes it hard to change in a consistent way.
–
Nick BerardiFeb 16 '09 at 14:17

9

I don't condone it, I'm just helping the guy out with his problem. Sometimes I preach, I just woke up and I'm not in the "extra mile" mood. Your post does the job, though. :)
–
Paolo BergantinoFeb 16 '09 at 14:20

Could you elaborate on how the onclick handler is evil? Is it just because of maintainability or is there a technical reason?
–
panziFeb 19 '12 at 1:38

2

+1 for cool kids comment as Jquery is very koowel.
–
MemeDeveloperMar 20 '12 at 20:16

I tried this but couldn't get it to work. The inline link above did work, and the two are practically identical. Here it is... jsfiddle.net/AndyMP/DBrf5
–
AndyDec 1 '11 at 12:18

@Andy: first of all you forgot to set the library to jQuery ;) Second, if you use it on your site you also need to wrap it in $(document).ready(function() { and });. (on jsFiddle it is onload so it does that for you)
–
NathanJan 1 '12 at 4:02