1

Within an .each(function(), I'm trying to uncheck checkboxes.
In line 1, I'm setting the value on 2 different Id's and this works fine. What I want to do, is to unset both of the checkboxes on a single line. i.e take lines 3 & 4 and combine into 1 line. Line 2 is what I've tried, but it's not working (it doesn't do either of them).
(The 'wsSeq' is created by the server side, so that I get unique ID's on multiple rows).

            $('#wsDocRef,#wsSupp').val('');
//          $("'#wsTransferToQuarantine" + wsSeq + ",#wsTransferToSupplier" + wsSeq + "'").attr('checked', false);
            $('#wsTransferToQuarantine' + wsSeq).attr('checked', false);
            $('#wsTransferToSupplier' + wsSeq).attr('checked', false);

2 Answers 2

1
$("'#wsTransferToQuarantine" + wsSeq + ",#wsTransferToSupplier" + wsSeq + "'").attr('checked', false);

That isn't too far off, except for the unnecessary quotes. If wsSeq is 1, your selector looks like this:

$("'#wsTransferToQuarantine1,#wsTransferToSupplier1'").attr('checked', false);

Which is fine, except for the ' at each end. This should work fine:

$("#wsTransferToQuarantine" + wsSeq + ",#wsTransferToSupplier" + wsSeq).attr('checked', false);

With all that said, however, it may actually be quicker to do two ID selections than one multiple selection. This kind of optimisation is probably not necessary or a good use of your time.

Sign up to request clarification or add additional context in comments.

3 Comments

When you say quicker, do you mean that the navigation of the DOM will be faster with 2 individual statements, rather than combining into 1 line? I assumed that by coding them together, that would be more the 'standards' of jquery.
@Keith Yes, quite plausibly – though you'd have to benchmark it, and that's more effort than it's worth. One ID selection can be handled by getElementById, which is ridiculously fast, while two has to be handled by querySelectorAll, which is only very fast.
Thanks. Wasn't aware of that. Oh well, I'll leave the 2 lines in there then but the question was answered....
0

Have you tried

$('#wsTransferToQuarantine' + wsSeq +',#wsTransferToSupplier' + wsSeq ).prop('checked', false);

You were just using two extra quotes in your call that are not needed

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.