0

I have found this: jQuery - Increase the value of a counter when a button is clicked and this JQuery Mouse Click counter

but does not work by me, i have tried this:

$("#btnplus").click(function(){
count =count +1;
$("#counterbox").html(count);
});

I have here a button and input box, button has id "btnplus" and input field "counterbox", i want if i clic on button to increase value of input, always +1, i don't get any error, what is here wrong?

4
  • Seem working to me Fiddle! I think you have not declared the variable count in the first place. Is it? Commented Jun 19, 2013 at 8:56
  • Can be a problem because i have input field and you use here a div to place counter value? Commented Jun 19, 2013 at 9:05
  • See this Fiddle. For input field you have to use val not html. Commented Jun 19, 2013 at 9:08
  • The Problem was <code>html</code>, for input is <code>val</code> to use, thanks to all Commented Jun 19, 2013 at 9:10

2 Answers 2

2

Try this

var count;

$("#btnplus").click(function(){
count =count +1;
$("#counterbox").html(count);
});

i think this should be work.

Sign up to request clarification or add additional context in comments.

Comments

1
var count = 0;
$("#btnplus").click(function () {
count = count + 1;
$("#counterbox").val(count);
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.