Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes, it resets the element's display property to the default by blanking out the inline "display: none", causing the element to fall back on its display property as defined by the page's ranking CSS rules.</p> <p>For example, here's a <code>&lt;div&gt;</code> with the ID of "myElement".</p> <pre><code>&lt;div id="myElement"&gt;&lt;/div&gt; </code></pre> <p>A <code>&lt;div&gt;</code> has a setting of <code>display:block</code> by default. In our style sheet, suppose we specify that your <code>&lt;div&gt;</code> is to be displayed as <code>table</code>:</p> <pre><code>div#myElement { display:table; } </code></pre> <p>Upon loading your page, the <code>&lt;div&gt;</code> is displayed as <code>table</code>. If you want to hide this <code>&lt;div&gt;</code> with scripting, you might do any of these:</p> <pre><code>// JavaScript: document.getElementById("myElement").style.display = 'none'; // jQuery: $("#myElement").toggle(); // if currently visible $("#myElement").hide(); $("#myElement").css({"display":"none"}); </code></pre> <p>All of thse have the same effect: adding an inline <code>style</code> property to your <code>&lt;div&gt;</code>:</p> <pre><code>&lt;div id="myElement" style="display:none"&gt;&lt;/div&gt; </code></pre> <p>If you wish to show the element again, any of these would work:</p> <pre><code>// JavaScript: document.getElementById("myElement").style.display = ""; // jQuery: $("#myElement").toggle(); // if currently hidden $("#myElement").show(); $("#myElement").css({"display":""}); </code></pre> <p>These remove the <code>display</code> CSS property from the inline <code>style</code> property:</p> <pre><code>&lt;div style=""&gt;&lt;/div&gt; </code></pre> <p>Since the inline style no longer specifies a <code>display</code>, the <code>&lt;div&gt;</code> goes back to being displayed as <code>table</code>, since that's what we put in the style sheet. The <code>&lt;div&gt;</code> does <strong>not</strong> revert to being displayed as <code>block</code> because our CSS overrode that default setting; blanking out the inline <code>display</code> property does not negate the rules in our style sheets.</p> <hr> <p>For giggles, here's the Google query I used for verification of my answer: <code>javascript style display empty string default</code></p> <p>...and a couple of links where this is mentioned:</p> <p><a href="http://jszen.blogspot.com/2004/07/table-rowsrevealed.html" rel="noreferrer">http://jszen.blogspot.com/2004/07/table-rowsrevealed.html</a></p> <p><a href="http://www.harrymaugans.com/2007/03/05/how-to-create-a-collapsible-div-with-javascript-and-css/" rel="noreferrer">http://www.harrymaugans.com/2007/03/05/how-to-create-a-collapsible-div-with-javascript-and-css/</a> (not in the article, but in the comments section)</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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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