Trying to check if span
.woocommerce-Price-amount
contains 19.76. I don't think it's working since there is <span class="woocommerce-Price-currencySymbol">$</span>
before the value I'm trying to target.
How can I ignore the currencySymbol span?
jQuery(document).ready(function($) {
$(".ivpa_term").click(function() {
setTimeout(function() {
$(".woocommerce-Price-amount").each(function() {
var inner = $(this).text();
if (!isNaN(inner) && 19.75 < inner && inner <= 19.76) {
console.log("Exists!");
}
});
}, 0001);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span class="quantity">2 ×
<del>
<span class="woocommerce-Price-amount amount">
<span class="woocommerce-Price-currencySymbol">$</span> 21.95
</span>
</del>
<span class="woocommerce-Price-amount amount">
<span class="woocommerce-Price-currencySymbol">$</span>19.76
</span>
</span>
I am no regex expert but you could try this if you just want to remove the dollar and get the digits
jQuery(document).ready(function( $ ) {
$( ".ivpa_term" ).click(function() {
setTimeout(function() {
$(".woocommerce-Price-amount").each(function () {
var inner = $(this).text();
var numb = inner.match(/\d+\.+\d+/g); //CHECK FOR NUMBERS AND DECIMALS
numb = numb.join("");
if (!isNaN(numb) && 19.75 < numb && numb <= 19.76){
console.log("Exists!");
}
});
}, 0001);
});
});
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments