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

  • Home
  • SEARCH
  • 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 9193495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:10:44+00:00 2026-06-17T21:10:44+00:00

i have one counter for script but i want to use the same for

  • 0

i have one counter for script but i want to use the same for counter.
i am open for all changes in class and id.
here is the code:

$(document).ready(function(){
    $('#target').click(function() {
        $('#output').text(function(i, val) { return val*1+1 });
    });

    $('#targetdown1').click(function() {
        $('#output').text(function(i, val) { return val*1-1 });
    });
    });

here is the example:

http://jsfiddle.net/cY9p7/7/

  • 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-06-17T21:10:45+00:00Added an answer on June 17, 2026 at 9:10 pm

    One of the solution i am using not just for your case, is to write the target id of an element i need to update as an attribute on the initiate element

    In your case i have added an data attribute on each +/- sign that indicate what is the target element needed to update

    HTML Code

    <div class="left" id="output1">1</div>
    <div class="right">
       <div class="up-arrow" id="target" data-target="output1">+</div>
       <div class="down-arrow" id="targetdown1" data-target="output1">-</div>
    </div>
    

    Jquery Code

    $(document).ready(function(){
        $('.up-arrow').click(function() {
            var target = $(this).attr("data-target");
            var val =  
    
            $('#' + target).text(function(i, val) {return val*1+1 });
        });
    
        $('.down-arrow').click(function() {
            var target = $(this).attr("data-target");
            $('#' + target).text(function(i, val) { 
                if (val == 0)
                    return 0;
                return val*1-1 
            });
        });
    });
    

    Fiddle Example

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

Sidebar

Related Questions

I have one problem with parsing *.docx document with OpenXML (C#). So, here's my
i have script that append sections(div) to my page $(document).ready(function () { var counter
I have one user (only one, all the others are fine) trying to update
I have two XML sources to retrieve data from. I want to use them
I have a ajax image upload script which i found here http://www.fengcool.com/2009/06/ajax-form-upload-local-image-file-without-refresh/ The problem
I have written a very simple page counter and a logging script that increments
I have been doing some customization to this jQuery paging script I found here
I have a vba script which is supposed to copy data from one sheet
I'm fairly new to PHP, but have managed to set up a script that
I have a script: http://jsfiddle.net/bXJhe/7/ jQuery(document).ready(function() { timer(10) }); // Timer var GLOBAL_TIMER; function

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.