webpage interactivity Flashcards
what does document.getElementById() return
a single element and null if its not found
what does document.getElementByClassName() return
a collection of all elements with the class
what does document.getElementByTagName() return
a collection of all elements with the tag
what does document.querySelector() return
first matching element of the selector
what does document.querySelectorAll() return
all matching elements of the selector
what are events
user interactions or browser actions that js can detect and respond to
in which two ways can we attach events to elements
inline event handlers
using addEventListener()
inline event listeners
events are added in html attributes
what is the issue with using inline event handlers
mixing js and html may be hard to maintain
what is the benefit of using addEventListener()
allows you to have multiple event listeners for an element
what is react
open source js library for ui components
how is react declarative and what are the benefits of this
makes code more predictable and easy to debug as it automatically updates the dom to match the components state
how is react component-based and what is the benefit of this
builds encapsulated components that manage their own state
each component can be reused meaning more manageable code
what are components and what can they accept
modular reusable units (functions/classes) that come together to form the ui
they can optionally accept an input and return a react element
what does a react element do
defines how a specific part of the code should be displayed
what is a state
a js variable managed by react to store a components dynamic data
what makes a state different to other js variables
persists across re-renders; when the state changes react automatically re-renders the component to reflect the new state
what are props(properties)
a way to pass data from a parent to child component
allowing components to communicate
what is a benefit of using props
makes components reusable and dynamic by allowing different values to be passed in
jsx
allows you to write html-like code inside js
used by react components to represent the markup that is rendered by react into the browser