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 7800439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:38:19+00:00 2026-06-02T00:38:19+00:00

I have the following HTML markup. <div class=caption> <img class=’active’ alt=’My Caption’ src=’path/to/image’ />

  • 0

I have the following HTML markup.

<div class="caption">
    <img class='active' alt='My Caption' src='path/to/image' />
    <div>My Caption</div>
</div>
<div class="caption">
    <img alt='My Caption 2' src='path/to/image' />
    <div>My Caption 2</div>
</div>

The captions are being placed inside those DIVs from the alt tags with some JS.

        $('#slider img').each(function() {
            $(this).wrap('<div class="caption"></div>').after('<div>' + $(this).attr('alt') + '</div>');
            $('.caption').width($(this).width()).children('div').each(function() {
                $(this).css({width: $(this).siblings('#slider img').width() -10, opacity: 0.5, display: 'block'});
            });
        });

The problem I’m having is when trying to make my images ‘slide’, it worked fine before but now I’ve added the captions I’m having some trouble.

Here is what is supposed to happen:
It goes through each image setting the class to active and fading the image in, it worked fine without captions but now that I have captions it is putting the active class on the div that has the caption in it.

Here is my JS

function simpleSlider(){
    var $active = $('#slider img.active');

    if($active.length == 0) $active = $('#slideshow img:last');

    var $next = $active.next('img').length ? $active.next()
        : $('#slider img:first');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active');
            $active.css({opacity: 0.0});
        })
}

How would I make it select the next image, instead of the div saying My Caption?

Sorry if this doesn’t make much sense.

  • 1 1 Answer
  • 1 View
  • 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-06-02T00:38:21+00:00Added an answer on June 2, 2026 at 12:38 am

    When you are saying:

    var $next = $active.next('img').length ? $active.next()
            : $('#slider img:first');
    

    it assumes that the next image is a direct neighbor (so that $active.next('img').length will always be 0 in your case as there are no images around). But since you have wrapped your images inside a container element you will now have to use a different approach for traversing.

    I would do it the following way:

    function simpleSlider() {
    
    
        var $active = $('.caption.active');
    
        if ($active.length == 0) $active = $('.caption:last');
    
        var $next = $active.next('.caption').length ? $active.next() : $('.caption:first');
    
        $next.css({
            opacity: 0.0
        }).addClass('active').animate({
            opacity: 1.0
        }, 1000, function() {
            $active.removeClass('active');
            $active.css({
                opacity: 0.0
            });
        })
    }
    

    See a working demo

    EDIT:

    In case these images are overlaid and the hidden image should always fade over the already shown image you can fix this easily by doing:

    a. move the line $active.removeClass('active') outside of the callback

    and

    b. add the following CSS:

    .caption{
    z-index: 100;
    }
    .caption:not(.active){
    z-index: 0;
    }
    

    Note that the :not() pseudo selector does not work in all browsers (i.e. old IEs), but you’ll get the idea.

    Here’s another fiddle

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following HTML markup, <div id=subcontent_l> <p> <a href=/membership-packages/><img height=202 width=644 alt= src=http://74.52.72.231/wp-content/uploads/2010/06/banner1.jpg
I have the following html markup: <div class=wrap_select> <span class=select id=selectdateRange>Today, 25 March, Sun</span>
I have following HTML <tr id=r1 class=l1> <td><img class=plusminus id=r1c1 src=assets/images/plus.png border=0 />3/10/12</td> <td></td>
I have the following HTML markup: <body> <div class=wrapper> <div class=head> <p class=title>title</p> <a
I have the following HTML markup: <div class=votes meta engagement> <span class=vote-count> <span class=vote-total>
I have the following html markup on my page, <div id=sig_container> <div id=layer1 class=layer
I have the following HTML markup, <section> <img width=106 height=113 title=key-staff-tim alt=key-staff-tim class=attachment-post-thumbnail wp-post-image
I have the following HTML markup: <div class=drag a></div> <div class=drop a></div> I also
I have the following HTML markup: <div id=step1 class=step> <h1>Enter code</h1> <p><input type=text value=<%=
I have the following HTML markup: <select name=Fault class=textbox id=fault> <option>Single Light Out</option> <option>Light

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.