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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:36:56+00:00 2026-05-13T12:36:56+00:00

I pretty new to js and jquery so please bear with me. I’d like

  • 0

I pretty new to js and jquery so please bear with me.

I’d like to change the background-position and add 1% on #div1 while clicking on #button1 and take -1% on #div1 while clicking on #button2

How could i achive this in jQuery?

Alse, bonus question:
These are going to get dynamically generated through php. Is it possible to use php in the js-script so the id’s get correct?

like this:

$i = 1
while($i <= 5):
 $div[$i] = 'div'.$i;
 $leftbutton[$i] = 'leftbotton'.$i;
 $rightbotton[$i] = 'rightbotton'.$i;
$i++;
endwhile;

Else i’ll have to learn how to make loops in js as well 😉

Edit: Follow up questions:

How can i update a text field with this value as i click the buttons? And how do i modify it if i’d like to add up/down buttons as well? thanks a bunch!

Thanks in advance!
-Simon

  • 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-13T12:36:56+00:00Added an answer on May 13, 2026 at 12:36 pm

    Like this:

    function makeClicker(index) {
        $('#leftbutton' + index).click(function() {
            var bPos = $('#div' + index).css('background-position');
            bPos = bPos.replace(/%/g, '').split(' ');
            bPos = (-1 + parseInt(bPos[0], 0)) + '% ' + bPos[1] + '%';
            $('#div' + index).css('background-position', bPos);
        });
        $('#rightbutton' + index).click(function() {
            var bPos = $('#div' + index).css('background-position');
            bPos = bPos.replace(/%/g, '').split(' ');
            bPos = (1 + parseInt(bPos[0], 0)) + '% ' + bPos[1] + '%';
            $('#div' + index).css('background-position', bPos);
        });
    }
    
    for(var i = 1; i <= 5; i++)
        makeClicker(i);
    

    EDIT: Fixed mistakes.

    Demo

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

Sidebar

Related Questions

I'm pretty new to jQuery, so please forgive... I have a page with a
So I am pretty new to JQuery and just spent 5 hours getting this
I am pretty new to JQuery and I'm working on a menu based on
I'm pretty new to programming and html design and would like to ask a
I'm new to jquery and i'm trying to make a dropdown menu list like
I'm pretty new to jquery so I'm proud of myself for what I've figured
I'm very new to jQuery and trying to run a pretty simple jQueryUI dialog
I'm pretty new with installing jQuery plug-ins, and I've only gone so far as
I'm pretty new with JQuery and I'm having trouble creating a behaviour that would
I'm pretty new to my company (2 weeks) and we're starting a new platform

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.