Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>These days with show / hide javascript, I prefer to use HTML5's data-* attributes.</p> <p>This can already be used in non-HTML5 browsers via the getAttribute and setAttribute function.</p> <p>I've quickly tried it against IE7, Chrome and Opera and it seems to work.</p> <p><a href="http://jsfiddle.net/ThJcb/" rel="nofollow">http://jsfiddle.net/ThJcb/</a></p> <pre><code>function showHide(shID) { var exDiv = document.getElementById(shID); if(exDiv.getAttribute("data-visible") != 'false'){ document.getElementById(shID+'-show').style.cssText = ';height:auto;opacity:1;visibility:visible;'; document.getElementById(shID).style.cssText = ';height:0;opacity:0;visibility:hidden;'; exDiv.setAttribute("data-visible" , 'false'); } else { document.getElementById(shID+'-show').style.cssText = ';height:;opacity:0;visibility:hidden;'; document.getElementById(shID).style.cssText = ';height:auto;opacity:1;visibility: visible ;'; exDiv.setAttribute("data-visible" , 'true'); } } </code></pre> <p>This allows you to determine the state of the div without having to check for CSS values.</p> <p><strong>EDIT</strong>: As pointed out in the comments, a typo was on the hide link (onlick instead of onclick) which made it appear the above jsfiddle worked whereas it didn't. At least not exactly as I made an error in the logic, setting the "data-visible" to false instead of true.</p> <p>Here's an updated jsfiddle: <a href="http://jsfiddle.net/ThJcb/4/" rel="nofollow">http://jsfiddle.net/ThJcb/4/</a> (javascript snippet above updated also)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload