Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you are checking <strong>whether something exists</strong>, <strong>use <code>.length</code> property</strong>. <code>.length</code> property contains number of elements matching the selector.</p> <p>Watch <a href="http://jsfiddle.net/SkxwQ/" rel="nofollow">this jsfiddle</a> to see that <strong>without using <code>.length</code></strong>, you will always get <code>true</code> <strong>regardless</strong> of whether there is some element or not.</p> <p><strong>EDIT:</strong></p> <p>After rethinking this (your description, your code and what you really want to achieve) my opinion is that your code should look as follows (see <a href="http://jsfiddle.net/zVSpg/2/" rel="nofollow">this jsfiddle</a>):</p> <pre><code>$('#plusexp').click(function() { var $cols3 = $('.cols3'); if ($cols3.is(':visible')){ $('.cols4').show(); }; $cols3.show(); }); </code></pre> <p>The reason for that is:</p> <ul> <li><p>you show <code>cols3</code> anyway, because:</p> <ul> <li>if both <code>cols3</code> and <code>cols4</code> are visible, you show <code>cols3</code>,</li> <li>if only one is shown, you show this element (if this is <code>cols3</code>, you show it, but if this is <code>cols4</code>, then showing <code>cols3</code> does not change anything),</li> </ul></li> <li><p><code>cols4</code> is shown only when <code>cols3</code> is visible before clicking (if both are invisible, then only <code>cols3</code> is shown),</p></li> <li><p>it is better to cache elements (in this case there is only one variable: <code>$cols3</code>),</p></li> </ul>
    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. 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