Don't execute jQuery if div value is lower than £X.XX

I have a script that triggers a click on a page element (building an A/B test and need to bypass a certain page):

jQuery(document).ready(function() {
    setTimeout(function() {
        jQuery(".collectionTab").trigger('click');
    }, 0);
});

What I want to do is STOP this script from executing if the value within a div is below a certain value. I.e.

<div class="totalPrice">£19.99</div>

As the total price is below 20 I would then want to NOT exectute the script.

Can't seem to get anything to work as am just guessing, any ideas?

Answers


You can achieve this by parsing the text of .totalPrice to a float and comparing it. Try this:

jQuery(document).ready(function() {
    var price = parseFloat($('.totalPrice').text().substr(1));
    if (price >= 20) {
        setTimeout(function() {
            jQuery(".collectionTab").trigger('click');
        }, 0); 
    }
});

Need Your Help

Syntax error in Maya

python syntax-error maya

I wouldn't normally post something so seemingly basic but I've been puzzling over this all afternoon.

Use of conditional statements in Jasmine tests

javascript testing jasmine

I have two functions I want to test; one that runs only in "modern browsers" the other that runs only in "older" browsers.