So I have a variable that I am declaring at the top of the JS document:
var poll_answer = 2;
However later on in the code, I am trying to append a new element with jQuery and would like to make use of this variable albeit adding '1' each time it is appended.
This is the main function:
function add_poll_answer_add() {
jQuery('#poll_answers').append('<tr id="poll-answer-" Answer' + poll_answer+1 + '>
}
By default there are two 'answers' and hence the reason for setting the var at 2. But whenever someone appends a new element through a button, I would like them to see a new <tr> with the content Answer 2, 3, 4 etc. as they add more answers.
I get no errors in the debug console.
Hope this makes sense.
... Answer' + (poll_answer++) + '> ...you need to increment the counter variable itself, not just add to a static value.(++poll_answer)to get the number the question was trying to get