Skip to main content
codingCourses
  • HTML
  • CSS
  • JavaScript
  • PHP
  • JS Tutorial
  • JS Strings
  • JS Arrays
  • JS URLs
  • JS DOM
JavaScript
  • JavaScript Tutorial
  • var, let, and const
    Key Differences Between Variable Declarations
  • undefined Value
    A Value for Unassigned Variables
  • null Value
    A Value for Explicitly Representing No Value
  • undefined vs. null
    Comparing undefined and null Values
  • Strict Mode
    Understanding "use strict"
  • Prototype Inheritance
    Understanding Prototype Inheritance
  • Spread Syntax
    A Simple Way to Spread and List Object Values
  • Rest Parameters
    Functions with Variable Arguments
  • Control CSS Variables with JavaScript
    How to Access and Modify Them
  • Arrow function Expressions
    Arrow Functions vs. Regular Functions
  • Immediately Invoked Function Expressions
    Why Use Them?
  • length Property
    Understanding and Usage
  • typeof Operator
    Checking Data Types
  • for Loop
    The Essential Basic Loop
  • for...of Loop
    A Loop for Objects Iterable by Value
  • for...in Loop
    A Loop for Objects Iterable by Property (Key)
  • for...in vs. for...of Loop
    Key Differences Explained
  • while Loop
    A Loop That Runs While the Condition Is True
  • do…while Loop
    A Loop That Runs at Least Once
  • Labeled Statement
    A Statement with a Label
JavaScript Strings
  • String Reference
  • Template Literals
    Handling Strings with Template Literals
  • trim()
    Leading and Trailing Whitespace
  • toLowerCase()
    Convert a String to Lowercase
  • toUpperCase()
    Convert a String to Uppercase
  • includes()
    Checking if a String Contains a Substring
  • indexOf()
    Find First Substring Index
  • search()
    Searching for Matching Strings Using Regexes
  • replace()
    Replacing Text in a String
  • slice()
    Slice a String by Index Range
  • split()
    Splitting a String and Returning an Array
  • substring()
    Extract a Substring
  • match()
    Finding Matches with Regular Expressions
JavaScript Arrays
  • Array Reference
  • Array.isArray()
    Checking for Arrays
  • forEach()
    A Function to Loop Through Array Elements
  • map()
    Transforming & Mapping Array Elements
  • filter()
    Filter Elements with a Callback
  • find()
    Finding a First Element with a Callback
  • findIndex()
    Finding an Element's Index with a Callback
  • includes()
    Checking for an Element
  • indexOf()
    Find the First Index of an Element
  • slice()
    Extract Array Elements by Index Range
  • join()
    Joining Array Elements into a String
  • reduce()
    Reducing an Array to a Single Value
  • reverse()
    Reversing Original Array Elements
  • sort()
    Sorting Original Array Elements
  • concat()
    Concatenating Arrays or Arrays and Values
  • shift()
    Remove the First Element from an Array
  • pop()
    Remove the Last Element from an Array
  • unshift()
    Add Elements to the Start of an Array
  • push()
    Add Elements to the End of an Array
JavaScript URLs
  • JavaScript URL Reference
  • URL Encoding Functions
    encodeURI() vs. encodeURIComponent()
  • encodeURI()
    Encoding an Entire URL
  • encodeURIComponent()
    Encoding URL Components
  • URL Decoding Functions
    decodeURI() vs. decodeURIComponent()
  • decodeURI()
    Decoding URLs Encoded with encodeURI()
  • decodeURIComponent()
    Decoding URL Components
JavaScript DOM
  • JavaScript DOM Reference
  • getElementById()
    Find an Element by ID
  • getElementsByTagName()
    Find All Elements by Tag Name
  • getElementsByClassName()
    Find All Elements by Class Name
  • HTMLCollection
    An Object Containing Selected HTML Elements
  • NodeList
    An Object Containing Selected Nodes
  • HTMLCollection vs. NodeList
    Understanding the Concepts and Differences
  • querySelector()
    Select the First Element Using a CSS Selector
  • querySelectorAll()
    Select All Elements Using a CSS Selector
  • querySelector() vs. querySelectorAll()
    Key Differences Explained
  • closest()
    Finding the Closest Ancestor Element
  • getAttribute()
    Getting Attribute Values from Elements
  • setAttribute()
    Setting or Adding Attributes to Elements
  • removeAttribute()
    Removing Specified Attributes from Elements
  • hasAttribute()
    Checking If an Element Has an Attribute
  • toggleAttribute()
    Toggling a Boolean Attribute on an Element
  • Manipulating the Class Attribute
    classList Object
  • classList.add()
    Add Class Values to an Element
  • classList.remove()
    Remove Class Values from an Element
  • classList.toggle()
    Toggle Class Values on an Element
  • classList.contains()
    Check Class Values of an Element

JavaScript DOM Reference

JavaScript Next

Learn about DOM (Document Object Model) in JavaScript and how to work with them.

How to Work with the DOM in JavaScript
getElementById()
Find an Element by ID
The getElementById() function returns the Element object whose HTML id attribute value matches the specified string. If no matching element exists, it returns null.
getElementsByTagName()
Find All Elements by Tag Name
The getElementsByTagName() function returns an HTMLCollection object containing all elements that match the specified tag name. If no matching elements are found, it returns an empty HTMLCollection object.
getElementsByClassName()
Find All Elements by Class Name
The getElementsByClassName() function returns an HTMLCollection object containing all elements that match the specified class name. If no matching elements are found, it returns an empty HTMLCollection object.
HTMLCollection
An Object Containing Selected HTML Elements
The HTMLCollection is a collection of elements selected from an HTML document, arranged in the order they appear in the DOM.
NodeList
An Object Containing Selected Nodes
The NodeList is a collection of nodes selected from a web page, arranged in the order they appear in the DOM.
HTMLCollection vs. NodeList
Understanding the Concepts and Differences
When working with the DOM in JavaScript, multiple selected HTML elements are often returned as collections. These DOM collections include HTMLCollection and NodeList.
querySelector()
Select the First Element Using a CSS Selector
The querySelector() function returns the first element that matches the specified CSS selector within the HTML document or a specific element. Returns null if no match is found.
querySelectorAll()
Select All Elements Using a CSS Selector
The querySelectorAll() function returns a static NodeList containing all elements that match the specified CSS selector within the HTML document or a specific element.
querySelector() vs. querySelectorAll()
Key Differences Explained
The querySelector() function returns the first matching element, while the querySelectorAll() function returns all elements that match the specified CSS selector.
closest()
Finding the Closest Ancestor Element
The closest() function finds and returns the closest ancestor element that matches the given CSS selector. The element itself is also included in the search.
getAttribute()
Getting Attribute Values from Elements
The getAttribute() function retrieves the value of a specified attribute from a DOM element. If the specified attribute exists on the element, it returns its value as a string.
setAttribute()
Setting or Adding Attributes to Elements
The setAttribute() function sets an attribute on a DOM element. If the attribute already exists, its value is updated; otherwise, a new attribute is added with the specified name and value.
removeAttribute()
Removing Specified Attributes from Elements
The removeAttribute() function removes the attribute specified as a parameter from a DOM element. If the specified attribute does not exist on the element, it does nothing without throwing an error.
hasAttribute()
Checking If an Element Has an Attribute
The hasAttribute() function checks whether a DOM element has a specified attribute. It returns true if the element has the attribute, and false if it does not.
toggleAttribute()
Toggling a Boolean Attribute on an Element
The toggleAttribute() function adds a specified Boolean attribute to a DOM element if it does not exist, and removes it if it does. It returns true if the attribute is added, and false if it is removed.
Manipulating the Class Attribute
classList Object
The classList is an object that allows you to easily manipulate the class attribute of DOM elements. It provides several useful methods and properties for adding, removing, replacing, and checking class values.
classList.add()
Add Class Values to an Element
The classList.add() method adds the specified class value to a DOM element. You can add a single class value or multiple class values at once.
classList.remove()
Remove Class Values from an Element
The classList.remove() method removes the specified class value from a DOM element. You can remove a single class value or multiple class values at once.
classList.toggle()
Toggle Class Values on an Element
The classList.toggle() method adds the specified class attribute value to a DOM element if it does not exist, and removes it if it does. It returns true if the class value is added, and false if it is removed.
classList.contains()
Check Class Values of an Element
The classList.contains() method checks whether the specified class attribute value exists in a DOM element. It returns true if the value exists and false otherwise.
JavaScript Next

codingCourses offers coding tutorials made for everyone.
All materials and examples are continuously reviewed to prevent errors; however, complete accuracy cannot be guaranteed.
Therefore, please carefully test and review all materials and examples to ensure they are free of errors, bugs, or vulnerabilities before relying on them.
They are available under the Creative Commons Attribution 4.0 International

Copyright © codingCourses. All Rights Reserved.