Reputation: 37
I hope you can help me. At the moment I have this progressBar which is just using a predefined value on click, to show a percentage process in a div.
Button:
<a class="pbar" data-value="5" href="javascript:void(0)"></a>
and here the js code so far:
<script type="text/javascript">
progressBar(0, $('#progressBar'));
$('.pbar').click( function () {
progressBar($(this).attr('data-value'), $('#progressBar'));
});
</script>
What I want now is, that every time the button ".pbar" is clicked, the data-value will be added by 5. So I click the button once, the bar shows 5%, I click again, it shows 10%, again 15% and so on.
Would appreciate your help. Thank you. Maze
Upvotes: 1
Views: 476
Reputation:
Try this, hope it helps you
$counter = $('.pbar').val();
$('.pbar').click( function () {
$counter = $counter+5;
progressBar($counter, $('#progressBar'));
});
Upvotes: 1
Reputation: 3624
progressBar(0, $('#progressBar'));
$('.pbar').click( function () {
var currentVal = parseInt($(this).attr('data-value'));
if (currentVal <= 100)
{
currentVal = currentVal + 5;
progressBar(currentVal, $('#progressBar'));
$(this).attr('data-value', currentVal);
}
});
Upvotes: 0
Reputation: 1128
$counter = 5;
$('.pbar').click( function () {
$counter = $counter+5;
progressBar($counter, $('#progressBar'));
});
Upvotes: 1