The below function is used on the html page to show/hide more details about a comment. The issue is that when the read more link is clicked, the page always scrolls up to the top, therefore taking the user away from the actual comment they are trying to view.
Would it be correct to try and use return false;
in the code block below? if so where?
var collapseIt = function(){
var collapsedSize = '25px';
$('.item').each(function() {
var h = this.scrollHeight;
console.log(h);
var div = $(this);
if (h > 40) {
div.css('height', collapsedSize);
div.after('<a id="more" class="item" href="#">Read more</a><br/>');
var link = div.next();
link.click(function(e) {
e.stopPropagation();
if (link.text() != 'Collapse') {
link.text('Collapse');
div.animate({
'height': h
});
} else {
div.animate({
'height': collapsedSize
});
link.text('Read more');
}
});
}
});
};