I’m trying to add one to a number inside a p element with jQuery, but it doesn’t work.
$(document).ready(function() {
function addOne() {
var number = $('p').html();
return number++;
}
$('p').text(addOne());
});
You need to parse the number as an Int first, otherwise JavaScript is going to treat it like a string and concatinate it instead.
Also, you want your function to return number + 1, or at least ++number, otherwise you’re incrementing after returning, and not actually getting the modified value.
Try this: