Quiz
- Is there a reason why we would use event handlers over just editing with css and js?
To make the page dynamic and user-interactive. If we want to do things in response to an action by the user, we have to use JS and event handlers.
- I'm still unclear why we'd want to add data- attributes.
I still feel a bit iffy on data attributes. Can we go over more examples where they're used?
Because we often want to store information in the web page. We could store it elsewhere, but it can be convenient to store it in the HTML of the page.
For example, in Ottergram, we stored the URL and ALT text for the big image.
- Maybe we could talk more about preventDefault()? / What are some other uses of event.preventDefault()?
When we work with front-end event handlers, we often attach those functions to widgets (UI elements) that already have a "normal" or "default" behavior. For example, hyperlinks or form submission buttons.
So, we often have to disable that normal behavior so that only our desired behavior happens.
- It'd be nice to walk through an example in class because reading through the example was a little tricky.
I'd be glad to!
- What is the difference between adding an attribute vs. adding a property?
Great question. I need to remind myself, and I found this great SO post about properties versus attributes in HTML. In short, attributes are the things in the tags in the HTML source, and properties are their JS equivalents in the DOM. Most are the same, but
value
might be different.Of course, you might mean CSS properties.
- The reading is very clear.
Glad to hear it!