javascript - Get the numbers inside two spans and do a calculation? -
i using wordpress plugin outputs numbers span elements. values of these span elements , divide 1 other, display result somewhere on site. don't know javascript, , have tried samples online, can't them work. can please explain how can done?
also note, these span elements doesn't have own id's, , because used in plugin, can't edit these directly, i'll need target them in order target each span individually:
.container1 .tooltip span .container2 .tooltip span
you can use parseint() if values don't have decimals:
var = parseint($('.container1 .tooltip span').text(), 10); var b = parseint($('.container2 .tooltip span').text(), 10); console.log(a - b); use parsefloat().tofixed(2); if values have decimals:
var = parsefloat($('.container1 .tooltip span').text()).tofixed(2); var b = parsefloat($('.container2 .tooltip span').text()).tofixed(2); console.log(a - b); prefixing + can change string number "0" value number 0 not 1 "$0".
var = +$('.container1 .tooltip span').text(); var b = +$('.container2 .tooltip span').text(); console.log(a - b); more can answered if add details tooltip.
Thanks for give us valuable information
ReplyDeleteWordPress Support Australia
WordPress Help