Should not be using aria-checked here in this way. Should be using the checked attribute as is shown in the checkbox spec on MDN.
let cloudPrivateCbxs = document.querySelectorAll('.cloud-private'); if (cloudPrivateCbxs && !cloudPrivateCbxs[0].checked) { cloudPrivateCbxs[0].click(); }
Here I used a useful variable names (never use single letter variable names except for simple counters like those in for loops), used querySelectorAll instead of getElementsByClassName, then I first check if the variable contains anything, then I simply check the checked attribute to see if it returns false. It is returning a boolean so I can use the logical NOT operator ! rather than check directly if it is equal to false.
this does not work: how does it fail? Does it do something else? How have you attempted to debug it? Is there an error in your console?z[0].aria-checkeddoesn't do what you think. You can't have-in an identifier, that's being treated as the subtraction:z[0].aria - checkedaria-checkedat all, should be using thecheckedproperty. Any question like this can be easily resolved by simply taking the time to read the spec on MDN: developer.mozilla.org/en-US/docs/Web/HTML/Element/input/…