I've got two code samples, the first one is working properly, the second one isn't. Both of them should increase a counter when I click on the #incrementBtn.
Here are the samples (and I will provide all the code for further clarifications):
1
$('body').on('click','#incrementBtn', function(){
let textAreaValue = parseInt($('textarea').val());
$('textarea').val(textAreaValue+1)
});
2
$('#incrementBtn').on('click', function(){
let textAreaValue = parseInt($('textarea').val());
$('textarea').val(textAreaValue+1)
});
And one more question, what is the difference between using this (code doesn't work):
let textArea = $(<'textarea'>);
let textAreaValue = parseInt(textArea.val());
textArea.val(textAreaValue+1);
And this (code works):
let textAreaValue = parseInt($('textarea').val());
$('textarea').val(textAreaValue+1)
Here is the full working code: https://jsfiddle.net/wjnjdk72/3/