So… basic problem statement, we have a checkBox, switch, button… whatever that we need to capture the click event and keep some state information about the object. I want to be able to click the object, save its state and not impact the rest of the items in the row.
I also need a way to find out which items are selected, since multiple items could be selected and it is the object that is selected not the row.
The first example is pretty straight forward, but then there are additional methods that I have added as a possible way to solve additional problems that come up when working with tables and objects in rows
In the table above, we are able to find the child elements because we know where we put it; also there is only one element.
1 |
tableRow.children[0] |
If there are multiple elements, one solution is to provide ids and then use a function like the one below to iterate through the child objects and find the one you are looking for.
Another thing that might come in handy is a method for finding which elements are selected
Final Solution with helpers included to show more fun stuff