The code runs through once, if at all. The console is silent. What's the problem?

The function hides the extra content under the spoiler automatically by adding a class and removing it when you click on the special div.

I tried using document ready, put in the bottom of the page, put in the beginning. In General, the script works on mood, it may, for example processing along the 10 sites on page 8, maybe all, maybe none.

$(function() {
$(".post-content").each(function(){
 var posc = $(this);
 if (posc.height() > 1000) {
posc.addClass('hide-content');
 posc.append('<div class="show-more-div">Expand</div>');
$(this).find(".show-more-div").click(function(){
posc.removeClass('hide-content');
$(this).remove();
});

}
});
});


Checked for conflict with other scripts (removed everything else), but the error continues.
August 23rd 19 at 10:57
2 answers
August 23rd 19 at 10:59
$(function(){}) calls the callback, after loading the document and building the DOM, but to download all other files (scripts, images, styles).
Try using $(window).on('load', function(){}).
August 23rd 19 at 11:01
All figured out. Forgot $(window).load(function() {

Find more questions by tags jQuery