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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:22:38+00:00 2026-05-27T04:22:38+00:00

I have the following question: I am working on a JQuery script that turns

  • 0

I have the following question:

I am working on a JQuery script that turns some HTML into a “Slider”. No problem so far, everything’s working smoothly.

The thing is is, if I want to run two or more “sliders” at the same time, of course they all “act” the same.

If I want them to act differently at the same time, can I “add” the script several times in the HTML-Code (, or do I have to add a “.each()” function, to the script?

HTML-Code:

<div id="galleria1" interval="1000">
            <a href="#" class="show" >
                <img width="640" height="450" rel="Slider-Image"src="a.jpg" />
            </a>
            ...
</div>

<div id="galleria2" interval="1000">
            <a href="#" class="show" >
                <img width="640" height="450" rel="Slider-Image"src="b.jpg" />
            </a>
            ...
</div>

Would be cool of any of you knows a solution to this!

Thanks, Mario.

EDIT:

Here the Script:

$(document).ready(function()
{
    //checks if page is completely loaded
    slideshow();
});


function slideshow()
{
    //Sets all pictures opacity to 0
    $('#galleria a').css({opacity:0.0});
    //Sets the first picture's opacity to 1
    $('#galleria a:first').css({opacity:1.0});
    //Calls the gallery() function to run the slideshow, number gives time till next 'slide' im milliseconds
    setInterval('nextPicture()', 1000);
}

function nextPicture()
{
    //If no image hast the class 'show', takes the first picture
    var current = ($('#galleria a.show')? $('#galleria a.show') : $('#galleria a:first'));
    //Get next image, if reached the end of slideshow, starts from the begining
    var next = ((current.next().length == 0) ? $('#galleria a:first') : current.next()); 
    //Runs Animation and makes next picture visible, number gives fade in time
    next.css({opacity: 0.0})
        .addClass('show')
        .animate({opacity: 1.0}, 1000);
    //Hides last picture
    current.animate({opacity: 0.0},1000)
        .removeClass('show');
}

-> used the same id=”galleria” for both so far. (already changed this in the html above)

Thanks for the answers so far!

  • 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-27T04:22:39+00:00Added an answer on May 27, 2026 at 4:22 am

    Give your <div> elements a “class”, and have the script apply itself to all elements with that class.

    <div id="galleria2" class='galleria' interval="1000">
    

    Then in the script:

    $('div.galleria').each(function() {
      // whatever
    });
    

    You didn’t post the JavaScript code so the actuality might be a little different.

    edit — OK now that the code has been posted, I’d restructure it like this:

    $(document).ready(function() {
      $('.galleria').each(function() {
        var $galleria = $(this), $anchors = $galleria.find('a'), current = 0;
    
        function slideshow() {
          //Sets all pictures opacity to 0
          $anchor.css({opacity:0.0});
          //Sets the first picture's opacity to 1
          $anchors.eq(0).css({opacity:1.0});
          //Calls the gallery() function to run the slideshow, number gives time till next 'slide' im milliseconds
          setInterval(nextPicture, 1000);
        }
    
        function nextPicture() {
          var $prev = $anchors.eq(current);
    
          //If no image hast the class 'show', takes the first picture
          current = (current + 1) % $anchors.length;
    
          //Get next image, if reached the end of slideshow, starts from the begining
          var next = $anchors.eq(current);
    
          //Runs Animation and makes next picture visible, number gives fade in time
          next.css({opacity: 0.0})
            .addClass('show')
            .animate({opacity: 1.0}, 1000);
    
          //Hides last picture
          $prev.animate({opacity: 0.0},1000)
            .removeClass('show');
        }
    
        slideshow();
    });
    

    By nesting the functions inside the “.each()” iterator, they’ll operate on their own assigned “galleria” instance.

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

Sidebar

Related Questions

i've got the following Problem / Question: I have HTML Code like this: <div
I am altering the question now! I have the search working using the following:
Dear g++ hackers, I have the following question. When some data of an object
I have some code that I would swear was working a month ago. However,
I have a some html being generated by JQuery on a Share Point page.
I'm working on writing a drop-down menu with jQuery and I have a question.
I'm making a horizontal scroller using jQuery. I have it working using the following
I'm working with some web services that have already been created and I need
I've been using Jquery for some time now and I have a question concerning
I have a simple script in jQuery that works perfectly with jQuery 1.5.2 as

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.