Thursday, 15 May 2014

jquery - modify the data-donut attribute of the divs from javascript -



jquery - modify the data-donut attribute of the divs from javascript -

my javascript

var currentmonth= new date().getmonth(); if (demo.length >= currentmonth){ var d3data = demo[currentmonth];

// output ["23", "19"]

now need update output values #donut , #donut1 (data-donut="")

values coming json may alter according month

for reference have added fiddle http://jsfiddle.net/qh9x5/3166/

<div class="zipper"> <div class="current"> <div class="title_text">current</div> <div id="donut" data-donut="42"></div>///here in data-donut value </div> <div class="target"> <div class="title_text">target</div> <div id="donut1" data-donut="62"></div> </div> </div>

any help appreciated

you can utilize assign values array (assuming array result after parsing json)

var d3data = demo[currentmonth]; // assuming results in d3data = ["23", "19"]; $(document).ready(function() { $("div[data-donut]").each(function(i) { $(this).attr('data-donut', d3data[i]); }); });

the first value of array assigned first div , sec value sec one.

see jsfiddle

javascript jquery html css d3.js

No comments:

Post a Comment