Note that there are some explanatory texts on larger screens.

plurals
  1. POJQUERY - Specific values from same class elements
    primarykey
    data
    text
    <p><strong>EDIT: I was really tired last night, and wrote my jQuery out wrong, ".readMore" is always the trigger for it's respective div's animation. I apologize.</strong></p> <p>Hello Everyone,</p> <p>I would like to extract specific information from elements with the same class. I have multiple divs that contain varying amounts of text, thus, their heights vary as well. However, I have set the class associated with these divs to a height of 200px. At the bottom of each div, I have an absolutely positioned anchor, that allows the reader to expand(animate) the div to it's automatic/natural height.</p> <p>What I'd like to do is to find out the 'auto' height of the divs with the same class, store it, and then call on it later when a respective div's anchor is clicked. So far, I keep only getting one value or no value, whereas I'd like all of them.</p> <p>I've been using .each() recently, but to no avail. The real problem seems to be animating the divs, otherwise, it's no problem; just need to use .css() to set the height to auto. This would be a whole lot easier if you could animate your height to auto. I hope I'm explaining myself correctly. In any case, here's my code.</p> <p>HTML</p> <pre><code>&lt;div class="stretch"&gt; text &lt;a class="readMore"&gt;Read More&lt;/a&gt; &lt;/div&gt; &lt;div class="stretch"&gt; text &lt;a class="readMore"&gt;Read More&lt;/a&gt; &lt;/div&gt; &lt;div class="stretch"&gt; text &lt;a class="readMore"&gt;Read More&lt;/a&gt; &lt;/div&gt; </code></pre> <p>CSS</p> <pre><code>div.stretch {height:auto; width:100%; overflow:hidden; position:relative} a.readMore {position:absolute; left:0; bottom:0;} </code></pre> <p>JQuery</p> <pre><code>$divheight = //stored height of divs $allheight = $divheight + 100; //extra space to clear the anchor $(".h200").height(200); $(".stretch").addClass("h200"); //change height later, to be able to refer to automatic/natural height $(".readmore").toggle( function(){ $(this).parent('div').animate({height:$allheight}, 750); $(".readMore").text("Read Less"); }, function(){ $(this).parent('div').animate({height:"200px"}, 250); $(".readMore").text("Read More"); } ) </code></pre> <p>Thanks it advance, I really appreciate you even taking a look.</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