Q:

JQuery - is there a way to make less calls to the dom

i have this jquery function 
    function update_prices(that, current_id, quantity) {
         //that == $(this)
        var wrapper = that.parents(".wrapper");
        var standard = wrapper.find(".prettyCheckbox small:eq(0)").parents("span").parents("label").prev("input").val();
        var professional = wrapper.find(".prettyCheckbox small:eq(1)").parents("span").parents("label").prev("input").val();
        var premium = wrapper.find(".prettyCheckbox small:eq(2)").parents("span").parents("label").prev("input").val();
        $.get("/shop_possystems/index.php?route=module/cart/ajax_get_individual_prices&standard_id=" + standard + "&professional_id" + professional + "&premium_id" + premium + "&quantity" + quantity;
            function(data) {
                var standard_price = data[0];
                var professional_price = data[0];
                var premium_price = data[0];
        });
        wrapper.find(".prettyCheckbox small:eq(0)").text(standard_price);
        wrapper.find(".prettyCheckbox small:eq(1)").text(professional_price);
        wrapper.find(".prettyCheckbox small:eq(2)").text(premium_price);
        return true;
    }

and i feel like i am calling the same elements on the dom  more then i should ....is there anyone that can think of a better way to achieve what i want without making all these calls

A:

You could cache the prettyCheckBox items:
function update_prices(that, current_id, quantity) {

    //that == $(this)

    var $wrapper = that.parents(".wrapper"),
        $prettyCheckBox0 = $wrapper.find(".prettyCheckbox small:eq(0)"),
        $prettyCheckBox1 = $wrapper.find(".prettyCheckbox small:eq(1)"),
        $prettyCheckBox2 = $wrapper.find(".prettyCheckbox small:eq(2)"),
        standard = $prettyCheckBox0.parents("span").parents("label").prev("input").val(),
        professional = $prettyCheckBox1.parents("span").parents("label").prev("input").val(),
        premium = $prettyCheckBox2.parents("span").parents("label").prev("input").val();    

    $.get("/shop_possystems/index.php?route=module/cart/ajax_get_individual_prices&standard_id=" + standard + "&professional_id" + professional + "&premium_id" + premium + "&quantity" + quantity,
        function(data) {
            var standard_price = data[0];
            var professional_price = data[0];
            var premium_price = data[0];
    });

    $prettyCheckBox0.text(standard_price);
    $prettyCheckBox1.text(professional_price);
    $prettyCheckBox2.text(premium_price);

    return true;
}

Also, I fixed an error.  You had quantity; and it should be quantity,.

