Wednesday, 17 March 2010

removeParent

Nah, this isn’t about how your parents mess you up, it’s about JavaScript (or ECMAScript if you prefer). You know how GMail has that groovy thing where you can add a number of email addresses to a contact? There’s this cool bit where you can click on a [add] and another field appears below the email field. Besides the new email field there is a [remove] link which gets rid of it if’n you don’t need it. I spent ages trying to figure out how this was done and discovered that the way to do it is:

onclick="this.parentNode.parentNode.removeChild(this.parentNode);"

How cool is that?

No comments:

Post a Comment