Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

jquery if multiple values

I want to make a condition if a value is more than another value then the element will be disabled, but I am confused because the variable I want to compare has multiple values from foreach database, I have tried to make a condition using jquery but it takes the highest value of a variable.

 $(".fill-div").click(function () {
        var ongkirNum = parseInt( ongkir.replace('.',''));

        $('.diskon-data').each(function() {
            var minDiscount = $(this).data('minongkir');

            if (ongkirNum < minDiscount) {
                $(".diskon-data").addClass("disabled");
            }
            });

    });

The result I want is to disable certain elements that do not meet the conditions according to the conditions and enable other elements that do.

Please, help me 🙂

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You need to keep operating on this within your .each callback in order to make changes only to that particular element

$(".fill-div").on("click", function () {
  const ongkirNum = parseFloat(ongkir.replace(".", ""));

  $(".diskon-data").each(function() {
    $(this).toggleClass("disabled", ongkirNum < this.dataset.minongkir);
  });
});

Using $(".diskon-data") selects all the elements with that class.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading