Respond to a click ...basic

Here's a list.

Here's some buttons.

navigate my process

related content

The Explanation

All well and good, but it's time to get interactive.

I've set up a demo here where we have a list and some buttons. One button adds a list item. The other removes the last item from the list.

Clicky clicky. Fun!

Okay, pointless, but demonstrates use of the Element.addEventListener() method which takes, first, an event to listen for, and second, code to run when the event is heard. The function passed in is given as its one and only argument the Event object for the event, which we're not using in this example, but I've kept it in the sample code so we don't forget it's what we have to work with.

Now this is where I think something like jQuery once upon a time would give you something that essentially looked like a click() method directly on the element. Honestly I don't think it makes sense in the context of the library I'm fleshing out here to over-complicate things and turn Element.addEventListener('click') into Element.onClick().

So...I'm not going to. At least, for now. Maybe down the line I'll find something else I want to do here that a library function could help with, but this is a case where the default functionality of JS works just fine for my taste.