javascript - Functions not changing the second time its called Jquery/JS -
i'm new js , trying use functions call later different values. function seems applying first value in both instances.
html
<div class="quality"> <span id="quality" data-avgquality="28"></span> </div> <div class="cost"> <span id="cost" data-avgcost="50"></span> </div>
js
$(document).ready(function(){ var qualitydata = $("#quality").attr("data-avgquality"); var costdata = $("#cost").attr("data-avgcost"); function loaddata(id,data) { $("#"+id+"").animate({ "width" : qualitydata+"%" }, 1500 ); }; loaddata("quality",qualitydata); loaddata("cost",costdata); });
when run data value both comes 28%.
change
function loaddata(id,data) { $("#"+id+"").animate({ "width" : qualitydata+"%" }, 1500 ); };
to
function loaddata(id,data) { $("#"+id+"").animate({ "width" : data +"%" }, 1500 ); };
Comments
Post a Comment