I need to loop through a data array and set value for each div element, In the line
$(".rate-circle").data('value', value);
Presently I'm doing this using the code below, however with this approach the value set for my elements is the last element i.e. 35.
var val = [55, 70, 88, 35];//, function (i, l) {
$("div").each(function () {
$.each(val, function (index, value) {
$(".rate-circle").data('value', value);
$(".rate-circle").rateCircle({
size: $("#rate-circle-size").val(),
lineWidth: 4,
fontSize: $("#rate-circle-font-size").val(),
});
});
});
Suggest where am I going wrong, I need to loop through the array and get the values and to set value corresponding to each elements
.data()will set data for all the matched elements...jsfiddle.net/rayon_1990/z2wtajud.data()in your inner loop it sets every div.rate-circle 'data-value' attribute to the current value. You might want to give more details of your problem, like an example of the HTML in your page.