Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7171091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:20:38+00:00 2026-05-28T15:20:38+00:00

Seem to be stuck trying to only update images in a selected div, when

  • 0

Seem to be stuck trying to only update images in a selected div, when all the div names are the same.

<div class="collapse">img img img img img</div>
<div class="collapse">img img img img img img img</div>
<div class="collapse">img img img </div>
<div class="collapse">img img img img img img</div>

I have the data of the images set inside a data-src tag, and when the div gets expanded, it loads the images. However, since the divs have the same class name, when it goes to load the images in the expanded div, it loads all the images in all the collapse divs.

    $(function() {
      $('.collapse img').attr('src', function(index, src) {
         return this.getAttribute('data-src');
      });
    });

This is the code inside my expand code, how can it be changed to only load the images in the currently selected div?

Edit – Expand Code:

$.fn.toggler = function(options) {
    var o = $.extend({}, $.fn.toggler.defaults, options);

    var $this = $(this);
    $this.wrapInner('<a style="display:block; color: #fff; text-decoration: none;" href="#" title="Expand/Collapse" />');
    if (o.initShow) {$(o.initShow).addClass('shown');}
    $this.next(o.cllpsEl + ':not(.shown)').hide();
    return this.each(function() {
      var container;
      (o.container) ? container = o.container : container = 'html';
      if ($this.next('div.shown').length) { $this.closest(container).find('.shown').show().prev().find('a').addClass('open'); }
      $(this).click(function() {



        $(function() {
          $('.collapse img').attr('src', function(index, src) {
             return this.getAttribute('data-src');
          });
        });



        $(this).find('a').toggleClass('open').end().next(o.cllpsEl)[o.method](o.speed);
        return false;
    });
});};

Edit 2 – How the div gets expanded. Sorry, still pretty new to this site. Should have given more info.

This is the javascript at the top of the page:

  <script type="text/javascript">
    $(function() {
      $("span.expand").toggler({method: "toggle", speed: 0});
    });
  </script>

The span that gets clicked to expand the div:

<span class="expand">&nbsp;</span>

The span is set up in css to show an image as the background.

Edit: Found the solution.

I placed:

$(this).find('a').toggleClass('open').end().next(o.cllpsEl)[o.method](o.speed);

Above the show image code, so that it would toggle it open first before trying to load the images, and changed the load image code to:

    $(function() {
      $this.closest(container).find('.collapse:visible img').attr('src', function(index, src) {
         return this.getAttribute('data-src');
      });
    });

Thanks all 😛

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T15:20:39+00:00Added an answer on May 28, 2026 at 3:20 pm

    This is assuming that you are handling your expansion by clicking the div in question

    $(".collapse").click(function() {
        // code that handles expanding 
        // ....
    
        $(this).children("img").attr('src', function(index, src) {
            return this.getAttribute('data-src');
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on learning Objective-C/Coaoa, but I've seem to have gotten a bit stuck
I was trying to do this: <body> <div id=Page> <div id=TopBar> <div id=TopBarLogo> <img
I seem to be stuck in Kafka-land, with a java.lang.String that I can't seem
This is a followup to this question . I seem to be stuck on
I seem to be mentally stuck in a Flyweight pattern dilemma. First, let's say
I'm getting very stuck on something that should be very easy. I am trying
I have been stuck on this for a few days now and it is
Hi everybody I seem to be stuck and I hope you guys can help
I'm trying to self-teach myself C++, and once again I got stuck on something
I have a listing of custom post types and I'm trying to implement a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.