• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Javascript-backed custom tag to Show/Hide *any* nested HTML tag?

 
Johnny Caimbridge
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For most HTML tags, one can use javascript to change the visibility of the tag with style="display:none". I'm a newbie to web-development and I found this useful, so I wrote a custom tag which allows one to change the visibility of elements (similar to the JSTL <c:if> tag, but permitting javascript toggling of the display style). I wrote a tag like this because I wanted something that was general to all tags.

My solution to this was to have the custom tag introduce enclosing <div>s which the javascript will lookup via getElementById() and adjust the style tag appropriately (if this weren't so trivial, then I would include the code). The problem I'm finding with this is that some HTML tags don't permit a nested <div>. For instance, I wanted to conditionally display combo-box options (<select><option>...</select>), but it is against the standard to use a <div> in the immediate nested scope of a <select>. Likewise, I wanted to conditionally display <table> rows, but it is against the standard to nest a <div> within a <table>.

Is there any general solution to this for all tags? Or will I need to handle cases like the above individually? Is there a "special" HTML tag which is valid at any nested scope and to which styles can be applied?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64717
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you need divs? The display property can be adjusted for any element.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic