css - set label text to span width with javascript -
i want set specified label text span width here code. help.
function setbarwidth(labeltext, barelement, cssproperty, barpercent) { var listdata = []; $(labeltext).each(function () { listdata.push($(this).textcontent); }); var listmax = math.max.apply(math, listdata); $(barelement).each(function(index) { $(this).css(cssproperty, (listdata[index] / listmax) * barpercent + "%"); }); } setbarwidth(".style-1 span label", ".style-1 em", "width", 100); setbarwidth(".style-2 span label", ".style-2 span", "width", 55);
textcontent
dom property, $(this)
jquery object. should use this.textcontent
or $(this).text()
.
you can replace .each
.map
var listdata = $(labeltext).map(function() { return this.textcontent; }).get();
.get()
@ end necessary convert jquery collection ordinary array.
Comments
Post a Comment