i used to think javascript was kind of evil, but gmail's converted me. you can actually do a lot of cool stuff with it (much of it, incidentally, having to do with {display:none} in your stylesheet). anyway, so i got the idea that i could javascriptize the roots database, where clicking on some checkboxes would magically cause the pinyin to appear or disappear next to the chinese. simple enough, but i've spent about a week on it now, since it's more complicated than it looks:
first, i had to figure out that checkboxes trigger scripts through the onclick handler (not onchange). that's the correct way (and the way Safari does it).
but the main problem was changing the stylesheet on the fly, which apparently is hard to do. most people just sprinkle ID tags on their html objects, and change their styles kind of brute force. but i found out that was slow. it turns out the only way to do this is to reference the style rules by number, backwards.
http://www.quirksmode.org/dom/changess.html
quirksmode is a great site, by the way.
then, i thought i was done, when i realized that the popup menu had pinyin in it which needed to be shown/hidden too. so i tried setting the menu's options[n].text, but the html entities weren't being converted. as it turns out, you need to stick in the octal or unicode values into the javascript string to get it to show up properly.
all i can say is, thank gosh for google.

Leave a comment