Cookie Notice

As far as I know, and as far as I remember, nothing in this page does anything with Cookies.

2009/04/09

Investigating jQuery

So, you have a bunch of HTML elements. Let's say they're Fieldsets.

  1. <fieldset>  
  2.   <legend> x </legend>  
  3.   XXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXX  
  4. </fieldset>  
  5. <fieldset>  
  6.   <legend> x </legend>  
  7.   XXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXX  
  8. </fieldset>  
  9. <fieldset>  
  10.   <legend> x </legend>  
  11.   XXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXX  
  12. </fieldset>  


Now, you want to be able to hide some of those fieldsets. You could make the legend clickable.

  1. <fieldset id="target">  
  2.   <legend onclick="hide_element('target')"> x </legend>  
  3.   XXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXX  
  4. </fieldset>  


hide_element() is dead easy. I do it in five lines. I could drop one if I wanted. Just a bit of stylesheet manipulation. But there's a problem. As written, that hides the fieldset for good. I really want to toggle. So, something must remain.

  1. <fieldset>  
  2.   <legend onclick="hide_element('target')"> x </legend>  
  3.   <div id="target"> XXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXX </div>  
  4. </fieldset>  


This is better, but you have to name every single fieldset. There should be a way to address everything anonymously. And there is. jQuery. Which I don't quite grok yet. But that's where my head is.

No comments:

Post a Comment