I am creating a new Wordpress widget. Its configuration form within the icons admin panel includes category and subcategory dropdowns (these aren't Wordpress groups).

The values of these dropdowns have to be retrieved via AJAX, plus altering the course dropdown should load new values in to the subcategory dropdown also via AJAX. To do this, I have to use jQuery to focus on the present dropdowns, and hang a handler for that change event.

How do i obtain the right jQuery selector in Wordpress to do this? The consumer will add a number of these icons towards the sidebar, and so i can't make use of a generic ID or CSS class. Or it is possible to more modest method to code this, maybe using wordpress_localize_script?

There needs to be some unique factor among the course dropdowns (because you say creating a selection there'd load options inside the subcategory).

I'd make use of the data() approach to attach this excellent identifier (may it be an id, or whatever) to all these pulldowns, in addition to affixing a category to each one of the pulldowns (mywidgetname-category, or whatever).

Then iterate over each one of the elements that suits your class, affixing a big change() event handler that then reads the initial identifier you attached using data(), and modifies the right subcategory choose.