mercredi 30 décembre 2015

else if statement - contains word remove or add class jquery

The last else if contains "Arriving" the string is actually "Arriving date" but I only want to find the first word and then do the logic for adding and removing classes. But I feel I'm not using the .length() correctly for this last one. can you guys help me understand how to test this correctly. the first two conditions work fine.

 jQuery("#custcolmen_size, #custcolmen-width").change(function () {

                               if($('.stock-message > span:contains("Out of stock")').length){ 
                                    $(".add2cart-div > input").addClass('disabled').removeClass('cart');
                                    $(".stock-message > span").addClass('alert alert-danger');
                                } 

                                else if($('.stock-message > span:contains("")').length) {
                                    $(".add2cart-div > input").removeClass('disabled').addClass('cart');
                                    $(".stock-message > span").removeClass('alert alert-danger');
                                 }

                                 else if($('.stock-message > span:contains("Arriving")').length) {
                                    $(".stock-message > span").addClass('alert alert-danger');
                                 }
                            });

Aucun commentaire:

Enregistrer un commentaire