Here is my html:
<a href="#">Read more</a>
<div class="moreDetails">
<p class="additionalText">Some text help here, random length.</p>
<p class="author">
<span class="bolder"><a href="minidashboard.php?user_url=http://url.people/1332517">Name</a>
</span>
</p>
<div class="replies">
<span>
<a href="topic.php?id=http://url/topics/1049198">1</a>
</span>
</div>
Im then using jQuery to add a class to the .additionalText div when its text is longer than 36 chars.
jQuery:
$('.moreDetails p.additionalText').filter(function () {
if ($(this).text().length > 32) {
$(this).addClass('trim');
}
});
What I now want is when <a href="#">Read more</a> is clicked the class .trim to be removed and reveal the content.
.trim sets the paragraph to a fixed height with overflow set to hidden.
You can give that link a class, like this:
then add a click handler, like this:
This works by finding the
<div>relative to the<a>via.next()and.find(). If the<div>doesn’t immediately follow the<a>like in your posted code this may need some tweaks, for example if there are elements in-between but they’re still siblings you’d need.nextAll('.moreDetails:first')instead of.next().