Recently I have been working with the Chrome Plugin API and I am looking to develop a plugin which will make life easier for me for managing a website.
Now what I wish to do is to fire an event when a certain checkbox is checked.
As this website does not belong to me I cannot change the code therefore I am using the Chrome API. One of the main problems is that rather than there being an ID, there is a Name. I was wondering if I could fire the function once the certain checkbox with the ‘name’ is checked.
Short answer: Use the
changeevent. Here’s a couple of practical examples. Since I misread the question, I’ll include jQuery examples along with plain JavaScript. You’re not gaining much, if anything, by using jQuery though.Single checkbox
Using
querySelector.Single checkbox with jQuery
Multiple checkboxes
Here’s an example of a list of checkboxes. To select multiple elements we use
querySelectorAllinstead ofquerySelector. Then useArray.filterandArray.mapto extract checked values.Multiple checkboxes with jQuery