Get product price from javascript in magento

To get the product price dynamically from the javascript, use id “product-price-{productid}”. Magento product.js file use this id to update the price when changing the product options. Use this sample code to get the product price.

<script>
var pricepattern = <?php echo json_encode(Mage::app()->getLocale()->getJsPriceFormat()) ?>;
var pricesymbol = '<?php echo Mage::app()->getLocale()->currency($currency_code )->getSymbol() ?>';
var prodpriceelement = '<?php echo "product-price-".$product->getID()?>'; 
var prodtaxelement = '<?php echo "price-including-tax-".$product->getID()?>';
(document.getElementById(prodpriceelement) === null) ? prodelement=prodtaxelement : prodelement=prodpriceelement;
document.observe("dom:loaded", function() {
	currentprice = gePrice(prodelement);
});
function gePrice(id){  
			var ds = pricepattern.decimalSymbol,
			gs = pricepattern.groupSymbol,
			pf = pricepattern.pattern;
			var price = 0; 
			$(id).innerHTML.replace(new RegExp("'\'"+gs,'g'),'')
			.replace(new RegExp("'\'"+ds,'g'),'.')
			.replace(pricesymbol,'')
			.sub(/([0-9.,]+)/,function(matches){ 
				str = matches[1];
				 while (str.search(gs) >= 0) {
        			str = (str + "").replace(gs, '');
    			}
				price = parseFloat(str);
			});
			return price;
		}
Product.OptionsPrice.prototype.oldReloadPrice = Product.OptionsPrice.prototype.reload; 
Product.OptionsPrice.prototype.reload = function(){ 
	this.oldReloadPrice(); 
   currentprice = Math.round(gePrice(prodelement));
}
</script>    

The code will work for all products when tax applied or not applied. Enjoy!!!! 🙂