How do I create a <p>
tag dynamically and assign it to a var when I click it, it should go to a function goTo
and know in what <p>
I clicked, in order to access the index of the array lastGoals
.
And I have other problem, it is 30 in "30s" I do this function to update and when I click it call the function many times I updated with this function.
I know the i
is not in the scope of $(document).on();
there is other problem because if I put inside the for
it will be addind the click in a bad way I think.
var isFirstTime = true;
var text = '<p class="boxLastGoals">test</p>';
var size = lastGoals.length;
for (var i = 0; i < size; i++) {
if (isFirstTime) {
$('#listLastGoals').html(text);
isFirstTime = false;
} else {
$('#listLastGoals').append(text);
}
}
$(document).on('click', 'p.boxLastGoals', goTo(event, i));