Modify the height of every div after a successful ajax request

I need assistance in reducing the height of a div within an ajax response that has a class called .shorten-post, but I am unsure how to accomplish this task.

I specifically want to decrease the height only for those within the ajax response, not throughout the entire document.

Below is the script I am currently using to handle ajax requests:

var page = 1;

$(window).scroll(function() {
    if ($(window).scrollTop() >= $(document).height() - $(window).height() - 100) {
        page++;
        loadMoreData(page);
    }
});


function loadMoreData(page){
  $.ajax(
        {
            url: '?page=' + page,
            type: "get",
            beforeSend: function()
            {
                $('.ajax-load').show();
            }
        })
        .done(function(profcontent)
        {
            if(profcontent == ""){
                $('.ajax-load').html("No more records found");
                return;
            }
            $('.ajax-load').hide();
            $(profcontent).filter('.shorten-post').each(function(){
              if ($(this).height() > 100) {
                $(this).height(50).css({ 'overflow': 'hidden'});
                $(this).siblings('.toggle-shorten-post').show();
            }});
            $(profcontent).insertBefore("#post-data");

        })
        .fail(function(jqXHR, ajaxOptions, thrownError)
        {
              alert('server not responding...');
        });
}

EDIT

Here is a brief overview of the code related to my profcontent:

<div id="tu_mainpost_<?php echo($current_post['slug_unique']); ?>" class="tu-post">
    <div class="tu-post-header">
    </div>
    <div class="tu-post-image alt-grid shorten-post">
        <div class="row">
            <img class="img-responsive" src="<?php echo(base_url('assets/img/uploads/' . $current_post['source_img'])); ?>" style="width: 100%; height: inherit;">
        </div>
        <div class="row">
            <div class="col-md-12 tu-main-description" style="margin: 10px 0px;">
                <div class="tu-main-description">
                    <p class="wordbreak"><?php echo nl2br($current_post['description']); ?></p>
                </div>
             </div>
        </div>
    </div>
</div>

Answer №1

If you need to make changes to $(profcontent)


    if(profcontent == ""){
        $('.ajax-load').html("No more records found");
        return;
    }
    $('.ajax-load').hide();
    var $profcontent = $(profcontent);
    $profcontent.filter('.shorten-post').each(function(){
      if ($(this).height() > 100) {
        $(this).height(50).css({ 'overflow': 'hidden'});
        $(this).siblings('.toggle-shorten-post').show();
    }});
    $profcontent.insertBefore("#post-data");

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Retrieve values from numerical fields based on Button Click using jQuery

I have 20 fields (numbered 1-20) with corresponding submit buttons, each field containing different values. I need to retrieve the values of these fields for an AJAX post based on which button is clicked. For example: $(function(){ $("#addCommentButto ...

Clear SELECT After Submission

I have a jQuery script and need a function to reset the SELECT input after it has been submitted. <script> $(document).ready(function() { //elements var progressbox = $("#progressbox"); var progressbar = $("#progressbar"); var statustxt = ...

Looking for a JavaScript code to create a text link that says "submit"?

Here is the code I have, where I want to utilize a hyperlink to submit my form: <form name="form_signup" id="form_signup" method="post" action="/" enctype="multipart/form-data"> ... <input type="submit" value="Go to Step 2" name="completed" /> ...

Having difficulty incorporating external SASS styles into my React.js project

In most of my projects, I follow a similar process for importing SASS styles. First, I create my react app and then install SASS using the command npm install node-sass. Next, I import my SASS file into my app components as shown below: import React from & ...

Stream music from SoundCloud by simply clicking a button on an external source, no need

My post contains an embedded SoundCloud player using the following code: <iframe class="soundcloud_iframe" width="100%" height="166" scrolling="no" frameborder="no" src="'.esc_url('https://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcl ...

How can you implement CSS styling for Next.js HTML during server-side rendering?

Explore Next.js and observe the page request in the network tab. The preview displays not only the HTML but a fully pre-styled page as well. https://i.stack.imgur.com/deJLY.png When working with Styled-Components and Material-UI, they offer the ServerSty ...

Malfunctioning navigation buttons in the owlCarousel slider

I am using the Owl Carousel slider from . However, when I click the next button four times, it shows me the fourth element in the slider instead of moving to the next slide. The navigation buttons and dots on the carousel do not seem to work correctly. ...

I'm attempting to create a button that changes to a bold red color when the condition is met

I am currently working on developing web applications using the Pixabay API. My goal is to allow users to mark an image as a favorite and have the heart icon change color to red accordingly. However, I seem to be facing issues with this functionality. To ...

Creating a dropdown menu using jQuery

I have a situation where I am linking a dropdown menu to the "onChange" event of a textbox. The functionality works as expected, however, when I click the button associated with it, the click event is not triggered. Below is the script being used: <sc ...

Different sources for multiple iframes

Greetings everyone, I am facing an issue with multiple iframes on my page, each with a different src attribute. Despite specifying unique sources for each iframe, upon loading the page, they all seem to be loaded with the same src. <html><body&g ...

Steps for choosing all choices in a multi-select menu without changing the order

What is the best way to choose all the options from a multiselect box using Java Script? ...

Issue with Django app: Bootstrap 4 modal hidden behind background

Having exhaustively researched this issue, I am still unable to resolve it with the outdated Bootstrap solutions available. The problem arises when I click on the button - the modal appears behind the background instead of in front. Most suggestions indica ...

Verify if the date string includes the day

Here's the scenario: a user clicks on one of two links, either 2012/10, or 2012/10/15. I am extracting the day value from the link to pass it onto an AJAX request that will change days on an archive page. Is using a regular expression like /\d{ ...

Trouble with Flex 3 styles not fully applying to dynamically generated tabs within a TabNavigator

When using ActionScript to dynamically create a tab, I noticed that the style is applied to the skins but not to the text of the newly created tab until I click on another tab and then go back to it. ActionScript private function clickAddTabHandler(event ...

unable to execute PHP code

I am attempting to execute a PHP file that will update a database. On Chrome, I am encountering this error: https://i.sstatic.net/3ruNL.png This is the code I have in my index.html file: <!DOCTYPE html> <html> <body> <input type ...

Guide to implementing jQuery autocomplete with an AJAX request to a PHP file

I'm currently working on implementing a jQuery autocomplete feature, and here is the code I have so far: $( "#text" ).autocomplete({ source: function( request, response ) { $.ajax({ type: 'GET', url: ' ...

Issue with Vuex not functioning properly in Nuxt.js

I'm facing an issue with setting the state in Vuex on my Nuxt.js App. It seems to not be working correctly. So, here is how I am trying to set the state using the fetch method: fetch({app, store, route}) { app.$axios.$get(`apps/${route.params ...

Enhance the current value through the use of .each() in JQuery

I'm currently working on a script that utilizes the .each() function to calculate the width of every image within the .item class. My goal is to gather all these widths and store them in a variable, which I then plan to pass outside of the function. H ...

Verify the accuracy of quiz responses with PHP and AJAX

I am working on a picture quiz that has one input field for each image. I am looking for a solution to verify if the value entered into the input field matches the correct answer. If it does match, I need to perform certain operations like adding or removi ...

What is the process for incorporating items from Slick Grid into a Multi Select TextBox?

Exploring the world of Slick Grid for the first time. Here is where I define my variables in JavaScript. var grid; var printPlugin; var dataView; var data = []; var selectdItems = []; var columns = [ { id: "Id", name: "Id", field: "Id", sortable: t ...