Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery for each function
    primarykey
    data
    text
    <p>I have added a show more or less function to a div - this all works fine however now i need to only allow this functionality if a element is over a certain height in this case. there are numerous classes of the same so i need to do the check on each element. although i am having problems getting it to work see code below : </p> <pre><code>$(document).ready(function() { $(".less").hide(); $(".more").each(function() { var actualHeight = ($(this).parent().parent().find('.appsList').height()); if (actualHeight &lt; 150) { $(".more").hide(); } }); $(".more").click(function() { var paragraphHeight = ($(this).parent().parent().find('.appsList').height()); if (paragraphHeight &gt; 150) { $(this).parent().parent().find('.appsHolderBody').animate({height:(paragraphHeight + 100) }); $(this).hide('slow'); $(this).parent().find('.less').show(); } return false; }); $(".less").click(function() { $(this).parent().parent().find('.appsHolderBody').animate({height:190 }); $(this).hide('slow'); $(this).parent().find('.more').show(); return false; }); }); </code></pre> <p>Any help would be greatly appreciated - please note when i am targeting the parent using .parent.parent i know its not pretty but could'nt get it to run using eq(4) for some reason.</p> <p>so the main problem is with this part of code</p> <pre><code>$(".more").each(function() { var actualHeight = ($(this).parent().parent().find('.appsList').height()); if (actualHeight &lt; 150) { $(".more").hide(); } </code></pre> <p>it hides all of the elements $(".more") instead of the ones that match the condition.</p> <p>html as requested</p> <pre><code>&lt;div class="appsHolder"&gt; &lt;div class="appsHolderBody"&gt; &lt;h5 class="appTitle"&gt;General Apps&lt;/h5&gt; &lt;ul class="appsList"&gt; &lt;li class="mainAppList"&gt;Resource Manager&lt;/li&gt; &lt;li&gt;&lt;a href=""&gt;Launch&lt;/a&gt; &lt;a href=""&gt;Info&lt;/a&gt;&lt;/li&gt; &lt;li class="mainAppList"&gt;Resource Manager&lt;/li&gt; &lt;li&gt;&lt;a href=""&gt;Launch&lt;/a&gt; &lt;a href=""&gt;Info&lt;/a&gt;&lt;/li&gt; &lt;li class="mainAppList"&gt;Yet Another App&lt;/li&gt; &lt;li&gt;&lt;a href=""&gt;Launch&lt;/a&gt; &lt;a href=""&gt;Info&lt;/a&gt;&lt;/li&gt; &lt;li class="mainAppList"&gt;Yet Another App&lt;/li&gt; &lt;li&gt;&lt;a href=""&gt;Launch&lt;/a&gt; &lt;a href=""&gt;Info&lt;/a&gt;&lt;/li&gt; &lt;li class="mainAppList"&gt;Yet Another App&lt;/li&gt; &lt;li&gt;&lt;a href=""&gt;Launch&lt;/a&gt; &lt;a href=""&gt;Info&lt;/a&gt;&lt;/li&gt; &lt;li class="mainAppList"&gt;Yet Another App&lt;/li&gt; &lt;li&gt;&lt;a href=""&gt;Launch&lt;/a&gt; &lt;a href=""&gt;Info&lt;/a&gt;&lt;/li&gt; &lt;li class="mainAppList"&gt;Yet Another App&lt;/li&gt; &lt;li&gt;&lt;a href=""&gt;Launch&lt;/a&gt; &lt;a href=""&gt;Info&lt;/a&gt;&lt;/li&gt; &lt;li class="mainAppList"&gt;Yet Another App&lt;/li&gt; &lt;li&gt;&lt;a href=""&gt;Launch&lt;/a&gt; &lt;a href=""&gt;Info&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div class="appsHolderExpander"&gt; &lt;a href="" class="more"&gt;More &lt;img src="/wps/PA_applicationsintros/./img/downArrow.png" /&gt;&lt;/a&gt; &lt;a href="" class="less"&gt;Less &lt;img src="/wps/PA_applicationsintros/./img/upArrow.png" /&gt;&lt;/a&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="appsHolderAdvertising"&gt; &lt;div class="appsHolderBody"&gt; &lt;h5 class="appTitle"&gt;Advertising Apps&lt;/h5&gt; &lt;ul class="appsList"&gt; &lt;li class="mainAppList"&gt;ATEX&lt;/li&gt; &lt;li&gt;&lt;a href=""&gt;Launch&lt;/a&gt; &lt;a href=""&gt;Info&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div class="appsHolderExpander"&gt; &lt;a href="" class="more"&gt;More &lt;img src="/wps/PA_applicationsintros/./img/downArrow.png" /&gt;&lt;/a&gt; &lt;a href="" class="less"&gt;Less &lt;img src="/wps/PA_applicationsintros/./img/upArrow.png" /&gt;&lt;/a&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>cheers in advance </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. 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