Stuff and Nonsense has a nice article using the DOM to simplify forms ... cool, but his JavaScript loops over form elements to set their display property to show/hide them (which everyone does, is simple to code/understand but is a tad inelegant!) Serendipitously (!) Sitepoint has a companion article that subtly uses CSS's descendant selectors (also known as contextual selectors e.g. in the W3C CSS 1 spec)so that all the JavaScript needs to do is change one class ... the form takes a "hide the optional bits" class which does nothing to it ;-) but the optional elements disappear due to a rule with a descendant selector rooted in the form's "hide optional" class ... excellent synergy! Using classes is such a better idea than manipulating element's style properties directly as -- ta da! -- it can be soooo easily adapted for media stylesheets, starting with print and moving on to anything! Nice one...
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment