Ignoring an specific element on javascript function

204 views Asked by At

I've got this javascript/xuijs function:

 function clearListBoxInputs(divelement,selected) {
    x$(divelement).find("input").each(function(element, index, xui) {
        x$(element).filter(function () {
                return this.checked;
            }).each(function (element, index, xui) {
                element.checked = false;
            });
   });
}

selected contains this value "input#Q1793_QO5527". divelement contains this value: "div#divQ1793". element is each element (checkbox) inside "div#divQ1793": "input#Q1793_QO5527", "input#Q1793_QO5528","input#Q1793_QO5529",... What I want to do is uncheck all input elements inside "div#divQ1793" except the one specified on selected ("input#Q1793_QO5527"). How can I ignore this one?

Thanks

1

There are 1 answers

0
Barmar On

You can use .not() to exclude a matching element.

function clearListBoxInputs(divelement, selected) {
    x$(divelement).find("input:checked").not(selected).prop("checked", false);
}

No need for all the .each and .filter loops, because .prop() automatically loops over all the elements.