Essential CSS
JavaScript Roadmap
Learn JavaScript
Mastering Web Typography
Practical Astro
Understanding Async JS
Unorthodox Tailwind
API Masterclass
Build and Deploy
The Beginner Freelancer
Real World Node
Profile Billing Logout
Learn JavaScript
Lesson Plan
  1. JavaScript and its ecosystem
    1. Welcome to Learn JavaScript!
    2. What is JavaScript used for?
    3. The JavaScript ecosystem
    4. Varying versions of JavaScript
  2. JS Basics
    1. Linking your JavaScript file
    2. Preparing your text editor
    3. The Console
    4. Comments
    5. On semicolons
    6. Strings, numbers and booleans
    7. Understanding Variables
    8. Understanding Functions
    9. The Flow of a Function
    10. Arrow functions
    11. Intro to objects
    12. If/else statements
    13. Comparing Objects
    14. The NOT operator
    15. Null and Undefined
    16. The BOM and the DOM
    17. Selecting an Element
    18. Changing Classes
    19. Listening to events
    20. Callbacks
  3. Building simple components
    1. How to think like a developer
    2. Starter files and Source codes
    3. Do this for every component
    4. πŸ›  Off-canvas menu: Building an off-canvas menu
    5. πŸ›  Modal: Building a Modal
    6. Lessons from the building process
    7. Debugging errors
    8. How to use a linter
  4. Arrays and loops
    1. Introduction to Arrays
    2. Array methods
    3. For loops
    4. The forEach loop
    5. Selecting multiple elements
    6. Nodes vs Elements
    7. πŸ›  Accordion: Building an accordion
  5. Dom basics
    1. Id, classes, attributes, and tags
    2. Changing CSS with JavaScript
    3. Getting CSS with JavaScript
    4. Changing Attributes
    5. Finding an element's size and position
    6. DOM Traversals
    7. πŸ›  Tabby: Building Tabby (A Tabbed component)
    8. πŸ›  Carousel: HTML and CSS
    9. πŸ›  Carousel: Switching slides with JavaScript
    10. πŸ›  Carousel: Working the dots
    11. πŸ›  Carousel: Positioning slides with JavaScript
  6. Events deep dive
    1. The listening element
    2. Default Behaviors
    3. Event propagation
    4. Event delegation
    5. Removing Event Listeners
    6. πŸ›  Modal: Closing the modal
    7. πŸ›  Accordion: Event delegation
    8. πŸ›  Tabby: Event delegation
    9. πŸ›  Carousel: Event delegation
  7. Transitions and Animations
    1. CSS Transitions
    2. CSS Animations
    3. Silky-smooth animations
    4. Integrating CSS transitions and animations with JavaScript
    5. Animating with JavaScript
    6. GreenSock Animation API (GSAP)
    7. πŸ›  Off-canvas menu: Animations
    8. πŸ›  Modal: Animating the modal
    9. πŸ›  Modal: Animating the pointing hand
    10. πŸ›  Modal: Animating the waving hand
    11. πŸ›  Modal: Wave hand animation with JavaScript (using GSAP)
    12. πŸ›  Accordion: Animations
    13. πŸ›  Carousel: Animations
  8. Useful JS features
    1. Ternary operators
    2. AND and OR operators
    3. Early returns
    4. Template Literals
    5. Destructuring
    6. Default parameters
    7. Enhanced Object Literals
    8. Rest and Spread
    9. Useful array methods
    10. Looping through objects
    11. Returning objects with implicit return
    12. πŸ›  Accordion: Using useful JavaScript features
    13. πŸ›  Tabby: Using useful JavaScript features
    14. πŸ›  Carousel: Useful JavaScript features
  9. JS Best practices
    1. Write declarative code
    2. Functions with a purpose
    3. Manage scope
    4. Reduce state changes
    5. Don't reassign
    6. Don't mutate
    7. Preventing Objects from mutating
    8. Preventing Arrays from mutating
    9. Write pure functions
    10. πŸ›  Accordion: Refactor
    11. πŸ›  Carousel: First refactor
    12. πŸ›  Carousel: Refactoring the dots part
    13. πŸ›  Carousel: Previous and next buttons
    14. πŸ›  Carousel: Second refactor
  10. Manipulating text and content
    1. Changing Text and HTML
    2. Creating HTML Elements
    3. Adding multiple elements to the DOM
    4. Removing Elements from the DOM
    5. πŸ›  Carousel: Creating dots with JavaScript
    6. πŸ› οΈ Calculator: HTML and CSS
    7. πŸ› οΈ Calculator: Happy Path
    8. πŸ› οΈ Calculator: Testing the Happy Path
    9. πŸ› οΈ Calculator: Easy Edge Cases
    10. πŸ› οΈ Calculator: Difficult Edge Cases
    11. πŸ› οΈ Calculator: Refactoring
    12. The switch statement
    13. πŸ› οΈ Calculator: Refactoring (Part 2)
    14. πŸ› οΈ Popover: Making one popover
    15. πŸ› οΈ Popover: Making four popovers
    16. πŸ› οΈ Popover: Making popovers with JavaScript
  11. Handling Forms
    1. Intro to forms
    2. Selecting form fields with JavaScript
    3. Form fields and their events
    4. Sanitize your output
    5. Generating unique IDs
    6. πŸ› οΈ Popover: Dynamic ID
    7. πŸ› οΈ Todolist: The HTML and CSS
    8. πŸ› οΈ Todolist: Creating tasks with JavaScript
    9. πŸ› οΈ Todolist: Deleting tasks with JavaScript
    10. πŸ› οΈ Typeahead: The HTML and CSS
    11. πŸ› οΈ Typeahead: Displaying predictions
    12. πŸ› οΈ Typeahead: Selecting a prediction
    13. πŸ› οΈ Typeahead: Bolding search terms
  12. Handling Dates
    1. The Date object
    2. Getting a formatted date
    3. Getting the time
    4. Local time and UTC Time
    5. Setting a specific date
    6. Setting a date with Date methods
    7. Adding (or subtracting) date and time
    8. Comparing Dates and times
    9. πŸ› οΈ Datepicker: HTML and CSS
    10. πŸ› οΈ Datepicker: Building the calendar
    11. πŸ› οΈ Datepicker: Building the datepicker with JavaScript
    12. πŸ› οΈ Datepicker: Previous and Next buttons
    13. πŸ› οΈ Datepicker: Selecting a date
    14. πŸ› οΈ Datepicker: Positioning the datepicker
    15. πŸ› οΈ Datepicker: Showing and hiding
    16. Formatting a date with toLocaleString
    17. setTimeout
    18. setInterval
    19. πŸ› οΈ Countdown timer: HTML and CSS
    20. πŸ› οΈ Countdown timer: JavaScript
    21. πŸ› οΈ Countdown timer: Counting Months
    22. πŸ› οΈ Countdown timer: Daylight Saving Time
    23. πŸ› οΈ Countdown timer: Counting Years
  13. Async JS
    1. Introduction to Ajax
    2. Understanding JSON
    3. The Fetch API
    4. Possible data types
    5. JavaScript Promises
    6. Requests and responses
    7. Sending a POST request
    8. Authentication
    9. Handling errors
    10. Viewing response headers
    11. CORS and JSONP
    12. XHR vs Fetch
    13. Using an Ajax library
    14. Reading API documentation
    15. Understanding curl
    16. πŸ› οΈ Todolist: The Todolist API
    17. πŸ› οΈ Todolist: Fetching tasks
    18. πŸ› οΈ Todolist: Creating tasks
    19. πŸ› οΈ Todolist: Editing tasks
    20. πŸ› οΈ Todolist: Deleting tasks
    21. πŸ› οΈ Todolist: Creating tasks with Optimistic UI
    22. πŸ› οΈ Todolist: Handling Optimistic UI errors
    23. πŸ› οΈ Todolist: Editing tasks with Optimistic UI
    24. πŸ› οΈ Todolist: Deleting tasks with Optimistic UI
    25. πŸ› οΈ Todolist: Refactor
    26. πŸ› οΈ Typeahead: How to add Ajax
    27. πŸ› οΈ Typeahead: Adding Ajax
    28. πŸ› οΈ Typeahead: Handling errors
    29. πŸ› οΈ Google Maps Clone: Creating your first Google Map
    30. πŸ› οΈ Google Maps Clone: Fetching JSONP via JavaScript
    31. πŸ› οΈ Google Maps Clone: Drawing directions
    32. πŸ› οΈ Google Maps Clone: Driving directions
    33. πŸ› οΈ Google Maps Clone: Handling errors
    34. πŸ› οΈ Google Maps Clone: Adding stopovers
    35. πŸ› οΈ Google Maps Clone: Refactor
  14. Advanced Async JS
    1. Requesting many resources at once
    2. Asynchronous functions
    3. Handling multiple awaits
    4. Asynchronous loops
    5. πŸ› οΈ Dota Heroes: Listing heroes
    6. πŸ› οΈ Dota Heroes: Filtering heroes (Part 1)
    7. πŸ› οΈ Dota Heroes: Filtering heroes (Part 2)
    8. πŸ› οΈ Dota Heroes: Refactoring
    9. πŸ› οΈ Dota Heroes: Hero Page
    10. πŸ› οΈ Dota Heroes: Making the hero page robust
    11. πŸ› οΈ Dota Heroes: Heroes page refactor
  15. Handling Keyboard Events
    1. Keyboard users
    2. Handling commonly used keys
    3. Keyboard events
    4. Understanding Tabindex
    5. Detecting the focused element
    6. Directing focus
    7. Preventing people from tabbing into elements
    8. How to choose keyboard shortcuts
    9. Creating single-key shortcuts
    10. πŸ› οΈ Off-canvas: Adding keyboard interaction
    11. πŸ› οΈ Modal: Adding keyboard interaction
    12. πŸ› οΈ Accordion: Adding keyboard interaction
    13. πŸ› οΈ Tabby: Adding keyboard interaction
    14. πŸ› οΈ Tabby: Refactoring
    15. πŸ› οΈ Carousel: Adding keyboard interaction
    16. πŸ› οΈ Carousel: Displaying help text
    17. πŸ› οΈ Calculator: Adding keyboard interaction
    18. πŸ› οΈ Popover: Keyboard
    19. πŸ› οΈ Popover: Refactor
    20. Keyboard shortcuts with Command and Control modifiers
    21. πŸ› οΈ Todolist: Keyboard
    22. πŸ› οΈ Typeahead: Keyboard
    23. πŸ› οΈ Typeahead: Selecting a prediction with the keyboard
    24. πŸ› οΈ Google Maps Clone: Keyboard
    25. πŸ› οΈ Dota Heroes: Keyboard
    26. πŸ› οΈ Datepicker: Tabbing in and out
    27. πŸ› οΈ Datepicker: Keyboard shortcuts
  16. Screen reader accessibility
    1. What is accessibility?
    2. How to use a screen reader
    3. Using NVDA
    4. Using Voiceover
    5. Aria roles
    6. Landmark roles
    7. Document structure roles
    8. Live region roles
    9. Widget roles
    10. Window and Abstract roles
    11. Accessible names and descriptions
    12. Hiding content
    13. ARIA properties and ARIA states
    14. ARIA for expandable widgets
    15. πŸ› οΈ Off-canvas: Accessibility
    16. ARIA for modal dialogs
    17. πŸ› οΈ Modal: Screen reader accessibility
    18. πŸ› οΈ Accordion: Screen reader accessibility
    19. ARIA for Tabbed components
    20. πŸ› οΈ Tabby: Screen reader accessibility
    21. πŸ› οΈ Tabby: Refactor
    22. πŸ› οΈ Carousel: Screen reader accessibility
    23. Roles that trigger Forms and Application modes
    24. What's next for accessibility?
  17. Handling Scroll
    1. The Scroll event
    2. πŸ› οΈ Auto-hiding Sticky-nav: HTML and CSS
    3. πŸ› οΈ Auto-hiding Sticky-nav: JavaScript
    4. πŸ› οΈ Auto-hiding Sticky-nav: Natural reveal
    5. Intersection Observer API
    6. Intersection Observer Options
    7. πŸ› οΈ Slide & Reveal
    8. πŸ› οΈ Slide & Reveal: Always fade-in when you scroll down
    9. πŸ› οΈ Slide & Reveal: Fine-tuning the animation
    10. πŸ› οΈ Infinite Scroll: Anatomy
    11. πŸ› οΈ Infinite Scroll: Infinite load
    12. πŸ› οΈ Infinite Scroll: Refactor
    13. πŸ› οΈ Infinite Scroll: Implementing the Infinite Scroll
  18. Mouse, Touch, and Pointer events
    1. Mouse Events
    2. πŸ› οΈ Spinning Pacman: HTML and CSS
    3. πŸ› οΈ Spinning Pacman: JavaScript
    4. Touch events
    5. Pointer events
    6. Touch-action
    7. πŸ› οΈ Spinning Pacman: Supporting Touch
    8. Cloning elements
    9. πŸ› οΈ DragDrop: HTML and CSS
    10. πŸ› οΈ DragDrop: JavaScript
    11. πŸ› οΈ DragDrop: Creating a drop preview
    12. πŸ› οΈ DragDrop: Sortable drop preview
    13. πŸ› οΈ DragDrop: Robustness
    14. πŸ› οΈ DragDrop: Refactor
  19. Object Oriented Programming
    1. Before we begin
    2. What is Object Oriented Programming?
    3. Four Flavours of Object Oriented Programming
    4. Inheritance
    5. This in JavaScript
    6. Call, bind, apply
    7. Creating Derivative Objects
    8. Composition vs Inheritance
    9. Polymorphism
    10. Encapsulation
    11. Closures
    12. Encapsulation in Object Oriented Programming
    13. Getters and Setters
    14. What OOP flavour to use
    15. When to use Object Oriented Programming
  20. Writing reusable code
    1. Creating reusable code by writing libraries
    2. Two Types of libraries
    3. Including libraries with Script tags
    4. Including libraries with ES6 Modules
    5. Dynamic imports
    6. πŸ› οΈ Off Canvas: Building a Library
    7. πŸ› οΈ Modal: Library setup
    8. πŸ› οΈ Modal: Opening the Modal
    9. πŸ› οΈ Modal: Closing the modal
    10. πŸ› οΈ Modal: Inheritance and Polymorphism
    11. πŸ› οΈ Modal: Resolving differences between subclasses
    12. πŸ› οΈ Modal: Exposing properties and methods
    13. πŸ› οΈ Accordion: Building a library
    14. πŸ› οΈ Tabby: Building a library
    15. πŸ› οΈ Carousel: Building a library
    16. πŸ› οΈ Calculator: Library
    17. πŸ› οΈ Calculator: Fixing the Clear Key
    18. πŸ› οΈ Calculator: Handling other keys
    19. πŸ› οΈ Calculator: State
    20. πŸ› οΈ Popover: Library
    21. πŸ› οΈ Popover: Adding event listeners
    22. πŸ› οΈ Typeahead: Library
    23. πŸ› οΈ DatePicker: Library
  21. Going from Vanilla JS to JS Frameworks
    1. πŸ› οΈ Building a Tiny framework
    2. πŸ› οΈ Tiny: Add event listeners
    3. πŸ› οΈ Tiny: Updating state
    4. πŸ› οΈ Tiny: Rendering Child Components
    5. πŸ› οΈ Tiny: Changing Parent State
    6. πŸ› οΈ Tiny: Passing Props
    7. πŸ› οΈ Tiny: Multiple Props
    8. πŸ› οΈ Tiny: Passing values from sibling components
    9. πŸ› οΈ Tiny: Mounting
    10. πŸ› οΈ Tiny: Passing props to descendants
    11. πŸ› οΈ Tiny: A tiny refactor
  22. Single Page Apps
    1. What is a Single Page App?
    2. Simple SPA using only CSS
    3. The Location Interface
    4. The History Interface
    5. Minimum viable server for a SPA
    6. πŸ› οΈ Dota SPA: Introduction
    7. πŸ› οΈ Dota SPA: Building The Heroes List
    8. πŸ› οΈ Dota SPA: Building the filters
    9. πŸ› οΈ Dota SPA: Filtering heroes
    10. πŸ› οΈ Dota SPA: Displaying filtered heroes
    11. πŸ› οΈ Dota SPA: Getting Ready to build the Hero Page
    12. πŸ› οΈ Dota SPA: Building the hero page
    13. πŸ› οΈ Dota SPA: Lore and abilities
    14. πŸ› οΈ Dota SPA: Routing for Single-page apps

Form fields and their events

10m:27s

Three types of fields are commonly used to build websites and web applications. We’ll be covering the first two in this lesson. They are:

  1. Input
  2. Textarea
  3. Select

Input

Input fields are the most versatile amongst the three types. They can be used to collect all sorts of information.

If you want to collect text information, you’ll set the input’s type to text.

<label for="username">Username</label>
<input type="text" name="username" id="username" />
Example of a text input

Other types of text-related input types that are well supported across browsers include:

  1. Email
  2. Number
  3. Password
  4. Tel
  5. Search
  6. Url

Different types of input gives you different effects. For example, if you set type="password", browsers will automatically hide the text entered by users:

<label for="password">Password </label>
<input type="password" name="password" id="password" />
Browsers mask password values automatically

If you set type="tel", browsers will launch a keypad instead of the standard keyboard on most mobile phones:

<label for="phone-number">Phone number: </label>
<input type="tel" name="phone-number" id="phone-number" />
Mobile browsers show a keypad when you set type to tel

If you set type="email" or type="url", browsers will automatically check if the entered values are valid email or url strings.

<label for="email">Email address: </label>
<input type="email" name="email" id="email" />
Browsers validate email addresses if type is set to email
<label for="url">Website: </label> <input id="url" name="url" type="url" />
Browsers validate urls automatically if type is set to url

You can safely use most input types to collect textual information. If a browser does not support the type you specified, it will revert to type="text" automatically.

(Note: For a list of all available input types, visit MDN’s input reference)

Getting values from textual input elements

To get the value from an <input>, you can use the value property.

<input type="text" name="text" value="Hello world!" />
const input = document.querySelector('input')
console.log(input.value) // Hello world!

You want to remove unnecessary whitespace from the start and end of the any value you obtain from a text field. To do so, you use the trim method that’s available for all strings.

<input type="text" name="text" value=" Hello world! " />
console.log(input.value) // " Hello world! "
console.log(input.value.trim()) // "Hello world!"

Input events

You can listen to four types of events for input fields:

  1. input
  2. focus or focusin
  3. blur or focusout
  4. change

input fires whenever a user types information into the field.

input.addEventListener('input', e => {
console.log(e.target.value)
})
input fires whenever a user types information into the field

focus and focusin fires whenever a user activates a field, either by tabbing into it or by clicking on it. The difference between these two events is: focusin bubbles but focus doesn’t.

input.addEventListener('focus', e => {
console.log(`Focus on! Value is: ${e.target.value}`)
})
focus fires whenever a user activates a field

focusout and blur activate when a field loses focus. The difference between these two events is: focusout bubbles but blur doesn’t.

input.addEventListener('blur', e => {
console.log(`Focus off! Value is: ${e.target.value}`)
})
blur fires whenever a user leaves a field

change fires whenever a value is committed by a user. They’re often used for other types of form fields, like checkboxes, radio buttons and select elements. For a text field, change acts the same way as focusout or blur.

Checkboxes

You use checkboxes if you want to let users toggle between on and off states. To create a checkbox, you use an input element with type set to checkbox.

<input type="checkbox" />
Example of a checkbox

Checkboxes require labels, or they wouldn’t make sense.

<input type="checkbox" name="checkbox" id="checkbox" />
<label for="checkbox">Label for the checkbox</label>
You tell a user what the checkbox is for through a label

Checkboxes are often used in tandem with other checkboxes. When you use them this way, make sure you use different name attributes for each checkbox.

<form action="#" method="post">
<p>Do you like these fruits?</p>
<div class="checkbox">
<input type="checkbox" name="apple" id="apple" />
<label for="apple">🍎 Apples</label>
</div>
<div class="checkbox">
<input type="checkbox" name="grape" id="grape" />
<label for="grape">πŸ‡ Grapes</label>
</div>
<div class="checkbox">
<input type="checkbox" name="lemon" id="lemon" />
<label for="lemon">πŸ‹ Lemons</label>
</div>
</form>
Checkboxes are often used together

Getting values from checkboxes

You can get the value of a checkbox with the value property.

<input
type="checkbox"
name="checkbox"
id="checkbox"
value="Have I been checked?"
/>
<label for="checkbox">Label for the checkbox</label>
const checkbox = document.querySelector('input')
console.log(checkbox.value) // Have I been checked?

If value is not set, value will default to on.

<input type="checkbox" name="checkbox" id="checkbox" />
<label for="checkbox">Label for the checkbox</label>
const checkbox = document.querySelector('input')
console.log(checkbox.value) // on

Selecting checked checkboxes

Checkboxes that are selected will have the checked attribute. You can select them through querySelector with the :checked pseudo class, through the checked property, or through the hasAttribute method.

Let’s say you have two items checked
// Selecting checked checkboxes through querySelector
const checkedCheckboxes = document.querySelectorAll('input:checked')
console.log(checkedCheckboxes) // NodeList(2) [input#apple, input#grape]
// Selecting checked checkboxes through the checked property
const checkboxes = Array.from(document.querySelectorAll('input'))
const checkedCheckboxes = checkboxes.filter(checkbox => checkbox.checked)
console.log(checkedCheckboxes) // [input#apple, input#grape]
// Selecting checked checkboxes through hasAttribute
const checkboxes = Array.from(document.querySelectorAll('input'))
const checkedCheckboxes = checkboxes.filter(checkbox =>
checkbox.hasAttribute('checked'),
)
console.log(checkedCheckboxes) // [input#apple, input#grape]

Checkbox events

You can listen to one event on checkboxesβ€”change. change fires whenever a checkbox gets checked or unchecked. Note: you can use an event delegation pattern since change bubbles.

form.addEventListener('change', e => {
const checkbox = e.target
console.log(checkbox.checked)
})
change fires when a checkbox gets checked or unchecked

Radio buttons

Radio buttons are used when you want a user to select one option from many options. To create a radio button, you use an <input> element with type="radio".

<input type="radio" />
A radio button

Like checkboxes, radio buttons require labels or they wouldn’t make sense.

<input type="radio" name="radio" id="radio" />
<label for="radio">Label for the radio</label>
A radio button with a label

Radio buttons are always used together with other radio buttons. A single radio button doesn’t make sense. When you use multiple radio buttons, make sure all radio buttons have the same name property.

You will need a value attribute for every radio button if you want to pass the selected radio value to the backend.

<form action="#" method="post">
<p>Select your favorite fruit</p>
<div class="radio">
<input type="radio" name="fav-fruit" id="apple" value="apple" />
<label for="apple">🍎 Apple</label>
</div>
<div class="radio">
<input type="radio" name="fav-fruit" id="grape" value="grape" />
<label for="grape">πŸ‡ Grape</label>
</div>
<div class="radio">
<input type="radio" name="fav-fruit" id="lemon" value="lemon" />
<label for="lemon">πŸ‹ Lemon</label>
</div>
<div class="radio">
<input type="radio" name="fav-fruit" id="none" value="none" />
<label for="none">😝 None of the above</label>
</div>
</form>
Radio buttons come as a group

Getting values from radio buttons

You can get the value of a radio button with the value property. Note: You can use an event delegation pattern since change bubbles.

<input
type="radio"
name="radio"
id="radio"
value="The best (only) radio channel in the world"
/>
<label for="radio">Label for the radio</label>
const radio = document.querySelector('input')
console.log(radio.value) // The best (only) radio channel in the world

The selected radio

The selected radio button will have the checked attribute. You can select it through querySelector with the :checked pseudo class, through the checked property or through the hasAttribute method.

Grape is selected
// Selecting checked radio through querySelector
const checkedRadios = document.querySelector('input:checked')
console.log(checkedRadios) // <input id="grape" name="grape" ... >
// Selecting checked radios through the checked property
const radios = Array.from(document.querySelectorAll('input'))
const radio = radios.find(radio => radio.checked)
console.log(radio) // <input id="grape" name="grape" ... >
// Selecting checked radios through `hasAttribute`
const radios = Array.from(document.querySelectorAll('input'))
const radio = radios.find(radio => radio.hasAttribute('checked'))
console.log(radio) // <input id="grape" name="grape" ... >

Radio events

You can listen to one event on radio buttonsβ€”change. change fires whenever a radio button gets selected.

const radios = document.querySelectorAll('input')
radios.addEventListener('change', e => {
if (e.target.checked) {
console.log(e.target.value)
}
})
change fires when a radio button gets selected

Textarea

Textareas are used to gather large amounts of textual information. They look like this:

<label for="long-text">Enter some text: </label>
<textarea name="long-text" id="long-text"></textarea>
Example of a textarea

Getting values from textarea

You can get the value of a <textarea> through the value property. When you do so, make sure you run trim on the value.

<label for="long-text">Enter some text: </label>
<textarea
name="long-text"
id="long-text"
value=" something goes here "
></textarea>
const textarea = document.querySelector('textarea')
console.log(textarea.value.trim()) // something goes here

Textarea events

You can listen to the event as text-based input elements. They are

  1. input
  2. focus
  3. focusout
  4. blur
  5. change

Refer to the input events section for an explanation for what each event does.

Wrapping up

Three types of fields are commonly used to build websites. They are:

  1. Input
  2. Textarea
  3. Select menu

When you work with <input> elements, make sure to use the correct type attribute.

Exercise

  1. Create a text field
    1. Get the value of the field when the input event occurs
    2. Get the value of the field when the focus event occurs
    3. Get the value of the field when focusout or blur events occur
  2. Create five checkboxes
    1. Check three of the five checkboxes
    2. Get checked checkboxes with JavaScript
    3. Get checked checkboxes when the change event fires
  3. Create five radio buttons
    1. Select a radio button
    2. Get the value of the selected radio
    3. Get the value of the selected radio when the change event fires
  4. Create a textarea
    1. Get the value of the textarea when the input event occurs
    2. Get the value of the textarea when the focus event occurs
    3. Get the value of the textarea when focusout or blur events occur