I’ve got a pie chart type thing and I need the value of it to change depending on what link is clicked (see link below and click button 70 to see what I mean)
http://fifamatchgenerator.com/dev/piechart/examples/
Here is the code which makes that work:
$('.updateEasyPieChart').on('click', function(e) {
e.preventDefault();
$('.percentage, .percentage-light').each(function() {
var newValue = document.getElementById(1).innerHTML;
$(this).data('easyPieChart').update(newValue);
$('span', this).text(newValue);
The (1) gets the ID of 1 from one of the sequential links on the page:
<li><a href="#" id="1" class="button updateEasyPieChart">70</a></li>
<li><a href="#" id="2" class="button updateEasyPieChart">60</a></li>
<li><a href="#" id="3" class="button updateEasyPieChart">50</a></li>
It obviously only works with the first link as it is only calling that ID. Now this is where I need the help. I need that value inside the document.get to be defined by the id of the link that is clicked, if you understand what I mean. So when the second link with the id of 2 is clicked, I will need that to be passed to the document.get and update. It sounds simple enough, but my javascript skills simply aren’t good enough to work it out on my own. Ive done a tonne of googling and can’t seem to find anything of use or that works. I’m not really looking for someone to do it for me, just point me in the right direction!
p.s. pie chart code I got from a website …but the code which changes the value (kinda) was written by myself and a friend.
This code is dynamic for any amount of links in the unordered list. It will grab the number from inside the inner html and update the pie chart. You might have to tinker with the updating the pie chart part, as I haven’t seen all the code 🙂
Here is the list, copied from your code
Here is the code that binds a click function to each anchor tag in the unordered list.