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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:08:21+00:00 2026-06-14T06:08:21+00:00

In javascript, I want to make a counter that increases the value when you

  • 0

In javascript, I want to make a counter that increases the value when you click a button.

When I click the add button the first time, the number doesn’t increase.

But when I print the value to the console, the result increases.

The fiddle: http://jsfiddle.net/techydude/H63As/

  $(function() {
    var //valueCount = $("counter").value(),
        counter = $("#counter"),
        addBtn = $("#add"),
        value = $("#counter").html();

      addBtn.on("click", function() {

      counter.html(value ++);  //this value is not incremented.
      console.log(value);      //this value gets incremented.
      return

    });

  });​

How do I make the value show the same for both lines?

  • 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-14T06:08:22+00:00Added an answer on June 14, 2026 at 6:08 am

    You are doing a Post Increment. Make it pre-increment:

    addBtn.on("click", function() {
      counter.html(++value);
      console.log(value);
      return
    });
    

    Explanation:

    // Increment operators
    x = 1;
    y = ++x;    // x is now 2, y is also 2
    y = x++;    // x is now 3, y is 2
    
    // Decrement operators
    x = 3;
    y = x--;    // x is now 2, y is 3
    y = --x;    // x is now 1, y is also 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make it so that on a first click i call one
I have a method: myMethod() {} that I want to make accessible to javascript.
I am studying jquery, I want make a effection as: first click, slider down
I want to make a javascript (or jquery) function that works onChange and allow
I want to make a new widget javascript class [Label] it look like dijit.button.
I want to make a JavaScript application that's not open source, and thus I
I want to make a javascript function that will prompt user to put space
I want to make a button generator with javascript in my site, something like
I am traversing a HTML document using javascript DOM. I want make a list
I want to make a variable length array in Javascript. Is this possible. 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.