It's not a secret anymore!*
The moose likes JSP and the fly likes Javascript-backed custom tag to Show/Hide *any* nested HTML tag? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Javascript-backed custom tag to Show/Hide *any* nested HTML tag?" Watch "Javascript-backed custom tag to Show/Hide *any* nested HTML tag?" New topic
Author

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

Johnny Caimbridge
Greenhorn

Joined: Nov 15, 2010
Posts: 8
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

Joined: Jan 10, 2002
Posts: 60782
    
  65

Why do you need divs? The display property can be adjusted for any element.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Javascript-backed custom tag to Show/Hide *any* nested HTML tag?
 
Similar Threads
customizing messages
onreadystatechange for div tag
Table in Javascript & HTML
Showing form elements on ajax call
Struts2 layout issue