I've designed a div element that initially displays only 180 characters, hiding the rest of the content.
When a user clicks on the 'viewmore..' link within this partially hidden div, all the content becomes visible and a 'showless...' link appears to revert back to the original state.
This final HTML structure utilizes JavaScript to control the hide/show functionality:
The 'shortcontent' div shows 180 characters, while the hidden 'allcontent' div holds the remaining text. The 'morelink' hyperlink toggles the visibility of the 'allcontent' div.
var html = '<div class="shortcontent" id="shortcontent">' + c +
'</div><div class="allcontent" id="allcontent">' + content +
//view more hyperlink
'</div><span><a href="javascript:void(0);" class="morelink">' + config.moreText + '</a></span>';
$this.html(html);
$this.find(".allcontent").hide();
$('.shortcontent p:last', $this).css('margin-bottom', 0);
I'm struggling to accurately measure the height of the 'allcontent' div after the user clicks the 'view more...' link. The current code returns 364px instead of the expected 1850px.
It seems like the height calculation is happening before the click operation is fully executed.
How can I ensure that the 'allcontent' container is completely expanded before retrieving its height in the click event below?
$(document).on( 'click', 'a', function () {
var explore = $('.allcontent').outerHeight( true );
//How do I wait for the click operation to complete here?
});
To help illustrate my issue, I've created a fiddle: