Get checkbox state using jQuery

Hi,
In my code I have:
<sp-checkbox id="cbAddWM" >Add WM</sp-checkbox>

I added a call to jQuery in my index.html:
<script src="./js/jquery-3.6.0.min.js"></script>

To set the initial state I use:
$("#cbAddWM").prop('checked', true);

Normally, to check if the checkbox is selected I use:
toggle = $("#cbAddWM").is(":checked");
However it is not working now and always yields false.

Therefore I use this:
toggle = document.getElementById("cbAddWM").checked

Why is toggle = $("#cbAddWM").is(":checked"); not working in PS UXP?

I don’t use jQuery so don’t know for sure, but does this help?

I am not familiar with jQuery but if you have only one checkbox you could do something as simple as this:

if(document.getElementById("cbAddWM").checked){
// do something
}

TBH, I don’t really see a point using jQuery nowadays. It used to be a life saver ~10-15 years ago, but now you can do basically all the same stuff with pure JS and UXP supports most of it. Is there some other specific case you want to use jQuery, that would be difficult with vanilla or is it just similar cases like checking if checkbox is checked?

1 Like

I didn’t think jQuery was supported in UXP yet? https://developer.adobe.com/photoshop/uxp/guides/uxp_guide/unsupported/

1 Like