Quiz
- I am still a bit confused with the Cloning Technique: why we need it and why we usually don't give a clone an ID?
We need it for the same reason we use copy/paste: sometimes its easier to copy something than to build it from scratch.
We avoid giving it an ID because then the copy will have the same ID and then the ID is no longer a unique identifier. (It's possible to generate a unique identify, but my experience is that students usually do better to avoid ID on cloned stuff.)
- Event delegation and the grocery example that goes along with it.
/ I hope we could practice delegation more.
Sure. Event delegation just allows us to replace lots of event handlers with a single one, attached to an ancestor.
For example, instead of every kid in a kindergarten class remembering their own handkerchief, the teacher has a box of tissues.
- Maybe we could talk more about event.target?
The event object is a bunch of information about the event, which the browser creates and gives as the first argument to the event handler.
The
event.target
is the actual DOM element that first got the event, which might be different from the DOM element handling the event, in the presence of bubbling.So, in our analogy of the kindergarten class,
event.target
is the kid who sneezed. - I'd love to understand more about searching up/down the tree with .closest/.find by walking through certain examples together
Sure. If we click on a button within a DIV, we often want to walk up the tree to find that DIV. We can use
closest
for that.Alternatively, if we are at the DIV, and we know that one of our descendants is a
P.count
we can.find()
that element, maybe to fill in a value.In the grocery example, we want to delete the item, so we go up from the button to the
LI
and delete the whole thing. - cloning, and general practice with everything in the reading. More examples and practice on cloning and on the new functions
We have an exercise coming up.
- All good for now! / So far so good!
Glad to hear it!