I have actually 2 questions,
First, I want to calculate a percentage in a html page and return it with javascript by appending it. This works fine but it sets everywhere the same value. I think I need something like 'this' but I can't find how to get it to work. The each function doesn't stay within is li, but sets its everywhere.
Another problem is the var getalfavconvert = parseFloat(getalfav.substring(1)); for some reason it returns a strange value. The var getalconvert = parseFloat(getal.substring(1)); on the other hand works fine. I think it has something to do with the a link.
Another problem is
$(".thing-shot ul").prepend('<li class="hammer">10%</li>');
$('.things li .group').each(function(index) {
// get value from page
var getal = $('.current-user-view').text();
var getalfav = $('.fav.marked a').text();
// convert value to float
var getalconvert = parseFloat(getal.substring(1));
var getalfavconvert = parseFloat(getalfav.substring(1));
//make a percentage calculation
var gedeeld = getalconvert/getalfavconvert;
var percentage = gedeeld*100;
// Set percentage in html
$(".hammer").text(percentage);
});
Here is the structure of li in the html:
<li id="screenshot-2081" class="group">
<div class="athing">
<div class="thing-shot">
<div class="thing-img">
<a href="go.html" class="link"><img alt="teaser" src="teaser.png?1310142565" /></a>
</div>
<ul class="tools group">
<li class="fav marked">
<a href="go.html">21</a>
</li>
<li class="cmnt current-user-cmnt
">
<a href="#">6</a>
</li>
<li class="views current-user-view">
276
</li>
</ul>
</div>
<div class="extras">
</div>
</div>
</li>
.shot ulrelated to.things li .group?