<bdi>
<span class="woocommerce-Price-amount amount">$</span>
"75.47"
</bdi>
Now i want to access bdi value that is 74.47 only, how can i fetch it by using jquery. Here is my jquery Code.
jQuery(document).ready(function($){
$('.qty').on('change',function(){
// grab the price
var price = $('bdi').children().not('span').html();
var total_price = price * this.value;
console.log(price, this.value, total_price);
});
})
4
Answers
Here is a one-liner. There are probably many other ways:
bdi
elementspan
from the cloneend()
to return to the cloned elementYou need to
.text()
method to grab thebdi
only and then use.replace
to remove the dollar sign$
as well the double quotes""
.Also, to remove the extra space we need to
.trim()
– In order to use maths we need convert the string tointegar
usingparseInt
methof to do themultiplication
and then get the totalvalue
in theconsole.log
Live Demo: (Full working code)
Using parseFloat Method to make sure the total in in
decimals
100.9 for 2 qtyLive Demo:
$(selector).text() will return value without html code in it.
Try
That will return "75.47", you can remove quotes and convert to double