I have this code in elementor custom code
<script>
jQuery(document).ready(function($){
$('#ship-price').on('click', function(){
var originalPrice = $('#product-price').val();
console.log(originalPrice);
//
var shipPrice = $('#ship-price').val();
console.log(shipPrice);
});
});
</script>
I’m trying to select two elements that I’ve added using elementor and where I have assigned a css id. It will occur that I’m unable to read the product price and ship price values.
What I need to achive is to show a different product price that is loaded using woocommerce, after the user click. How I can fix the problem?
UPDATE
this is the html of the product price
<div class="elementor-element elementor-element-2cf415f elementor-widget elementor-widget-heading" data-id="2cf415f" data-element_type="widget" id="product-price" data-widget_type="heading.default">
<div class="elementor-widget-container">
<h2 class="elementor-heading-title elementor-size-default"><span class="woocommerce-Price-amount amount"><bdi>499,00 <span class="woocommerce-Price-currencySymbol">€</span></bdi></span>*</h2> </div>
</div>
And this is the rendered html for the ship price I need to get
<div id="elementor-tab-content-3201" class="elementor-tab-content elementor-clearfix elementor-active" data-tab="1" role="region" aria-labelledby="elementor-tab-title-3201" style="display: block;"><ul>
<li><a href="#" id="ship-price-a">70€ + IVA</a> ...</li>
<li><a href="#" id="ship-price-b">79€ + IVA</a> ...</li>
</ul></div>
2
Answers
The product price seems to be within a heading element () and the ship price is within an anchor element (). To get the content of these elements, you should target the original price using
find()
andthis
to get the ship price and usetext()
instead ofval()
.Demo:
a) Since your Id’s are not straightforward so use
*
to match themb) Also, none of your prices is inside the input element, they are inside some HTML elements so use
.text()
rather than.val()
c) Product price is coming under the child element of the
#product-price
element so you have to modify that code too.Working snippet: