Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
568 views
in Technique[技术] by (71.8m points)

jquery - Increment a number inside a div?

i have this

<div class="likes">13</div>

and I want to increment this number by +1 when I click a button

How can I do that with jQuery?

$('btn').click(function() {
   $('.likes').text();
});
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
$('btn').click(function() {
  var el = parseInt($('.likes').text());
  $('.likes').text(el+1);
});

http://jsfiddle.net/jg5GA/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...