How to use jQuery .click () to add +1 to <span> when click on HTML <button>

1 Answer

0 votes
<!doctype html>
<html>
<head>
  <script src="js/jquery/1.11.3/jquery.min.js"></script>
</head>
<body>

<button>Click for +1</button> <br /><br />

<span>0</span>
<script>
$( "button" ).click(function() {
  addOne( $( "span" ) );
});
 
function addOne( elem ) {
  var n = parseInt( elem.text(), 10 );
  elem.text( n + 1 );
}
</script>
</body>
</html>

 



answered Aug 23, 2016 by avibootz
...