
Introduction to how JavaScript works and how you can write JavaScript code
JavaScript is a core technology on the web alongside HTML CSS
JavaScript runs in the browser and gets rendered by the browser within the HTML page.
You can connect to HTML elements, using the HTML DOM which is a programming interface for JavaScript to add, update and remove HTML elements.
HTML elements can be accessed as objects that have properties, methods, and events.
Code is a set of instructions that tells the application in a language that can be understood by it, what to do.
JavaScript code is single threaded, which means that only one thing can happen at a time on the thread. Other requests get blocked until an operation completes and then those requests will run.
How to write code using a code editor or IDE.
How the elements from the HTML code are represented within the DOM tree structure, and that you can navigate from one to another.
What Devtools are and how you can use them
How you can use console log and console dir methods within the DevTools to view the document object and see the contents of the page elements in the DOM.
How to add JavaScript code within your HTML file and run the JavaScript code in your browser.
JavaScript commenting in the code and how to make your code more readable.
HTML is the markup language used to structure and provide meaning to the web content. CSS is the language used that contains the rules for styling the HTML content. JavaScript is the scripting language that allows you to create interactive and dynamic content within the web page.
You can do a lot with JavaScript such as store values, run blocks of code, apply logic with conditions and add events to your page elements. There is a lot you can do with JavaScript and the possibilities are endless.
APIs- are sets of prebuilt building blocks that allow developers to connect into and access these objects. Think of it like a control panel which JavaScript language lets you interact with.
Browser APIs allow access to the web page elements, and other data. You can access the API and do useful programming things. The DOM ( Document Object Model) API allows you to manipulate the HTML and CSS of the page.
How to Add JavaScript to HTML
You can add JavaScript as an attribute inline to an HTML element although this format is not suggested. They are hard to identify and not good practice.
Internal JavaScript within the HTML script tags. Should be added just before closing the body tags, if you are going to be interacting with the page elements. The code loads into the browser from the top down, and if the HTML hasn’t fully loaded and you try to access the element using JavaScript you will encounter an error.
Best practice is with an external file, using the is extension. Place the script tags, and use the src attribute link to the path of where your file is located. It can either be relative to where the html file is or absolute using a file address including the full path to load it. If you use absolute then you should be able to paste the path into your web browser and see the file.
Example code to output text into a web page, using the document.write method.
Lesson JavaScript Coding Exercise :
Create an HTML file and a JS file.
Use the script tags to link to the JS file as the source file.
Using the document.write() add text to the webpage.
Using the document.write() add html formatted content to your webpage.
JavaScript Code Tips
Use Comments when possible single or multiple line
Indent using whitespace to make the code readable
Create code in a separate JS file and link to it from the HTML file
Use the console for debugging and to see values
Whitespace is ignored in the code, use whitespace and indentation to make the code more human readable. Be careful not to add spacing between the syntax statements, as this can cause errors when the code is being rendered. Blocks of code can be indicated using the curly brackets, this will be used within the various code syntax in the upcoming lessons.
Window object is the parent of the document object. The window object is the top parent and contains various methods that can be used. The alert() and the prompt() are both part of the windows object. You can use these to create an interaction with the user. Both will show a standard popup message in the browser, which must be actioned before the user can interact with the rest of the browser window. Although they provide a simple way to interact with the user, these are not commonly used, since the user experience is poor and there are more interactive options now in JavaScript and the DOM. Alerts and prompts are meant for interaction with the web user.
Start by creating an index.html and app.js file. Then write some JavaScript code and try it out. Open and run the HTML file in your browser. You can use the functions from the lesson such as alert() or document.write(‘Hello’); Alert stops the code execution, if on top it does not output the content until the button is clicked. Place JavaScript at the bottom so the rest of the code can render.
How to use variables in JavaScript
Variables are one of the basic concepts of coding
Using const or let avoid using var
const and let are scope based
Parent scope vs local scope
Assign values to variables and reassign new updated values
Use of strings and numbers as values for variables
Dynamic type with JavaScript changing data type
Math and output from JavaScript directly
Variables allow developers to hold values, these values can be updated as needed within the code. Typically variables are declared at the start of your code, and used throughout the code to hold application values. The values can change using “let” when you declare a variable. Use “const” when you want the value to stay the same throughout the code. This can save errors and issues with reassigning values mistakenly in the code.
Double quotes and single quotes or backticks can be used to contain string content. A semicolon is not necessary after a statement if it is written on its own line. But if more than one statement on a line is desired, then they must be separated by semicolons. It is considered best practice, however, to always write a semicolon after a statement, even when it is not strictly needed. Whitespace is ignored in JavaScript code, you can use it for writing code that is more readable and understandable.
Creating variables -
var - Declares a variable, optionally initializing it to a value.
let - Declares a block-scoped, local variable, optionally initializing it to a value. Blocks of code are indicated by {}
const - Declares a block-scoped, read-only named constant. Cannot be changed.
Variables must be declared before you use them. Comma separate to declare multiple variables. Camelcase is more readable as in the example below.
let a,b,c,d;
let userfirstname = “Laurence”;
let userFirstName = “Laurence”;
Lesson JavaScript Coding Exercise :
Declare variables both numbers and strings using both let and const
Try the various formats to create strings using the single, double quotes and backticks
Output the results into the console and to the document.
Assign new values to the variables and output the results
Try the template literal strings with JavaScript wrapped in the ${} and check the output in both the console and webpage
JavaScript Dynamic Type Conversion
What is JavaScript Dynamic Type Conversion and how it works
JavaScript DataType
Data Types string, number, boolean - typeof type conversion
Data Types Booleans Null Undefined
number.toString() Number(string)
typeof operator
Javascript variables can be converted in different data types, they are not set to the data type that they are declared with. JavaScript uses different data types, JavaScript dynamically assigns the data type that it presumes is desired, you can also change data types of the variable if needed.
Lesson JavaScript Coding Exercise :
Declare multiple variables without assigning values to them
Get the data type of a variable and output it to the page
Add numbers and strings together
Convert a string to a number
Convert a number to a string
Create boolean values
Variable naming Rules how to declare JavaScript Variables
Variable identifier names must use unique names
Variable identifier names should be meaningful and semantic if possible
Identifiers can contain letters, digits, underscores and the dollar sign
Variables names must begin with a letter, underscore or dollar sign
Names are case sensitive
Names cannot be the same as JavaScript reserved words
No spaces in the variable name
Rules for naming variables must start with a letter, underscore (_), or dollar sign ($). Subsequent can be letters of digits. Upper or lower case. No spaces. No limit to the length of the variable name. Variable names are case sensitive. Cannot use reserved words.
Lesson JavaScript Coding Exercise :
Create some string values
Assign meaning names to the variable identifier names
Use camelCase for a variable name
Arrays and Objects in JavaScript coding examples
Both arrays and objects in JavaScript provide a powerful way to hold content and use data within code. WIth one variable you can hold multiple values within both arrays and objects, in addition you can use combinations of these as they hold all data types, allowing the data contained within them to go multiple levels deep as needed. Arrays and objects can be declared using const as the variable points to a location within the memory and not the to value that it is assigned to, which makes it possible to update the objects and arrays contents without actually having to reassign the value to the variable. Typically if you do use an array or object then you won’t want to change it, as when you assign the variable a new value it would remove all the items contained within these.
Arrays are objects that have a preset order of items, using the index of the item to select and identify the item within the array list. Arrays also have built in methods which make them a powerful way to use the data and manipulate and select items contained in the array. Objects also can contain multiple items in the same variable, they are identified by a property name which is used in order to select the item from the object. Each property name can only be used once and is unique within the object. Property names can be set with quotes or as single words within the objects. They get assigned values as a pair with the property name, using the colon to assign the value and comma separate multiple named pair values.
Lesson JavaScript Coding Exercise :
Create an array with various data types.
Create an object with various data types
Retrieve a value from both the array and object and output it into the console.
Try using both dot notation and bracket notation to retrieve values within an object.
Update the values of the array and object using the index value for the array and property name for the object.
Declare a new variable and assign the existing array to the new variable. Make updates to the contents of the new variable and see how it also updates the first array.
JavaScript Functions how functions can be used in code
functions can be used to run blocks of code
two types of functions Function Expression and Function declaration
Functions can take
Function naming are the same rules as variables
You can pass in values into the function within the parentheses, parameter names can be separated by commas to add multiple values
When the function is invoked the parameters are known as function arguments which are the values received by the function in the parameters
Functions can return values, the return statement will end the function execution and return the value.
Functions have scope within the curly brackets. Local values within the function scope can only be accessed within the function
Benefit of functions is that you can write the code once and reuse it as many times as needed. You can get different results with different argument values and return values.
Functions allow developers to run a block of code,when the function is run it's defined invoking the function when it's executing the code. Functions provide a powerful way within code to run blocks of code, also they contain their own scope so variables set within the function can live only within that function. Create functions in code to do repeat code tasks, and handle specific coding objectives. You can pass values into a function then use those values within the function code, and return a result back from the function code. Functions can use arguments within the parameters, although they are not mandatory. Function also can use return although not mandatory to return a response from the function. You can pass values into function to be used within the code.
There are two types of functions, function declaration which uses the keyword function to assign the function code, or a function expression which is similar to assigning a variable a value, but in this case it's the function code.
// Function declaration
function test(num) {
return num;
}
// Function expression
var test = function (num) {
return num;
};
Lesson JavaScript Coding Exercise :
Create a global value that will be incremented every time the function is executed. Add this increment of the value to each function. counter++;
Create a function expression that within its code can output a value into the console
Invoke the function. Update the function with a parameter, where the function uses that argument value and outputs that value into the console
Create a function declaration. Add 3 parameters, that will take the value and add them all together. Use return to return the resulting total of the values that were passed into the function.
Assign the returned value of the function to a variable that is output into the web page.
JavaScript Document Object Model for interactive web pages
The Document Object Model (DOM) is an object that contains a data representation of the page elements. The DOM is structured in a tree like format, as objects that comprise the web page and content of the HTML web document. Document Object Model (DOM) is a programming interface for HTML documents, that is the logical structure of a page and how the page content can be accessed and manipulated. Bring your web pages to life with JavaScript and connect to the web page elements. Accessing the DOM you can create fully interactive content that responds to the user. DOM and Javascript lets you create Dynamic web page content that can change without page refresh and present new elements and updated content to the user. Improve your web users experience with JavaScript and the DOM. What is the DOM Document Object Model How to select elements from your webpage with JavaScript Manipulate and change your page elements with JavaScript How to set styling attributes for elements Make them interactive with Event listeners DOM events and Page events with JavaScript How to create elements with code and add them to your webpage Moving elements and animation of elements.
Lesson JavaScript Coding Exercise :
Create your HTML file add some page elements
Assign to a variable the document.body.children array which will represent all the child elements within the body.
To select the first one use the index value of 0, as just like arrays these are zero based. Output the object to the console with console.dir()
Select some properties from the element, output them into the console.
Update the textContent of the element to a value of your name.
Go to your favorite website and open the devTools, type the document.body.textContent = "Laurence Svekis"
DOM methods with JavaScript select HTML page elements
There are methods in the Document object that allow us to better select elements we want to manipulate with code. querySelector() and querySelectorAll() allow JavaScript to select page elements from the content within the document object.
JavaScript querySelectorAll Get Page Elements Select ALL. Use of querySelector and querySelectorAll to select matching page elements. Different selectors including tag, id, and class. Select page element, iterate contents of node list output and update page elements.
Lesson JavaScript Coding Exercise :
Update your HTML to include 2 div’s and an input element.
Using querySelector() and querySelectorAll() select all the page elements and assign variables to the page element objects.
Update the text content of the first element
Assign a value to the input element myInput.value
Update some of the style properties of the second div to make it look more like a button.
Add an event listener to the button, that assigns a function to the element click event onclick
Within the click function get the value of the input, update the textContent of the first div to be the value of the input field. Assign a black string to the input field value.
Logic Conditions with JavaScript if Statement Switch
Conditions can be used within code to apply logic, and run different actions based on the result of the condition. Depending on the value either True or False the code can run different blocks of code.
The if statement will check a condition, if true it runs the specified code. If false it does not run the code. Else provides an alternative if the condition is not true then else statement allows us to run a block of code on false if none of the previous conditions are true. You can also use the else if statement to check another condition with a separate block of code to be run if the previous condition came back as false.
Using the switch statement allows us to specify several alternatives checking to see if any of the conditions match and allow the corresponding code to be executed.
JavaScript code can use Comparison Operators to check if a statement is true or false. To check multiple conditions you can apply Logical Operators to check logic between conditions. The example below will show how to use the Logical operators and the results that can be expected with the various combinations of true or false.
Lesson JavaScript Coding Exercise :
Select the page elements you want to use assign variables to them
Create a global value for counter of 0
Once the button is clicked increment the counter by 1
Check to see if the counter value is less than 2, if that's true then update the style color to red
Add an else if to the condition, checking if the value of counter is less than 4, if it is then update the style color to green for the output element.
Add an else if to the condition, checking if the value of counter is less than 6, if it is then update the style color to purple for the output element.
Using else if none of the conditions are true update the style of the element to be blue
Create a switch to check for values of the counter. Create cases for the values you want to track, update the output area text with different string values depending on the case. Try the switch with and then without the break keyword.
Add in a default within the switch statement
Operators in JavaScript How to apply operators
Lesson JavaScript Coding Exercise :
Get the value of the input field. Convert the value to a number using the Number() method.
In the condition check if the result of the input is an actual number of NaN using the isNaN() method
Using the modulus check if the value of the input is odd or even. If it has a remainder then it will be odd otherwise it is even.
Perform math calculations on the input value and output the results back to the user in the output field.
Ternary Operator JavaScript Short one statement conditions
Lesson JavaScript Coding Exercise :
Get the value entered into the input field, check if it's a number. If it is not a number then in the condition update the output text with a message for the user. Change the style background and color of the output element.
If it is a number using the ternary operator create a output message to the user depending on the value that was entered into the input field
Check if the number entered is larger than 19 or equal to 19, and if it is then show a message that the person is allowed in. Otherwise deny entry for the person.
Math Random Values JavaScript get Random Numbers
Javascript Math object contains various methods that can be used for math functionality, in addition it also contains the random method that creates random values in JavaScript. The Math.random() method returns a floating-point number in the range 0 (inclusive of 0) to less than 1 (not including 1). The random value can then be multiplied and rounded to the nearest whole number to include the randomized range of values desired by the developer.
Random values are ideal for games and to create unique custom experiences for web users.
Random Number Interactive Guessing Game with JavaScript and the DOM coding exercise
In this exercise create a random number guessing game that will provide a random range of numbers that the user has to guess the correct number from. The application will provide the user feedback whether the guess was too high or too low, allowing for the user to narrow the range of the hidden number. Once the solution is found matching the input value to the hidden number, the game starts again generating the random number and a new range to guess. Feedback is provided to the user in the HTML element, so that the user playing the game knows the results and what to do next. This is a perfect example of a simple game that can be created with JavaScript and interacting with the DOM page elements.
Lesson JavaScript Coding Exercise :
Select the HTML page elements as variables within your JavaScript code.
Create declare variables globally for a lowValue, highValue, and hiddenNumber
Create a function to start the game called starter().
Create a function to generate random numbers using min and max values are parameters within the function. Wrap the Math.random() within the Math.floor() to round down to the nearest whole number. Math.floor(Math.random()). Multiply the random value by the max minus the minimum, to include the max value add plus 1 to the multiplied number. Within the result add 1 to increment from 0 to the starting value of the minimum number.
Within the starter() function, generate a low value, a high value and a hidden number value with random numbers.
Update the HTML output div to provide instructions for the user to guess a number between the random range.
For the input element, change the type to number, and set attributes to min and max from the random values.
Add an event listener for onclick to the button page element, once clicked the button should invoke a function called clickedMe()
Within the clickerMe() function get the input value.
Check if the hidden number matches the value of the input value. If it does then output is correct and run the starter function again.
If the guess is incorrect, check whether the guess is lower or higher than the hidden number value. If it's lower, update the lowValue with the input value, and provide feedback to the user to guess higher. If the guess is high, provide feedback to the user, and update the high value with the input value.
The game should continue until the correct number is guessed, once the correct number is found then the game will reset and run again with new random numbers.
JavaScript For, While Do While Loops Run blocks of code
Loops allow us to execute blocks of code a number of times, they also allow us to iterate through a list of items such as items in an array or other iterable list.
Loops will always require several parameters, such as a starting value, a condition to stop the loop and a way to move through the items to the next item in the loop. We can setup a simple for loop by setting a variable to use with a starting value, then applying a condition to continue the loop if the condition is true, and incrementing the value of the variable so that eventually the condition is no longer true.
Lesson JavaScript Coding Exercise :
Select the page elements as JavaScript variables
Update the input field attributes to be a number input type, with a min and max value.
Add a click event listener to the button element
When the button is clicked, get the input value as a variable called num. Create a for loop to iterate a block of code the number of times from the input num value.
Create a while loop that will output html the number of times from the input value.
Create a do while loop which will create the html output the number of times from the input.
Update the html with the new content.
JavaScript Objects how to use Objects in code
One of JavaScript's data types is an object. These can be used to store various keyed collections and even more complex entities. The document is a giant object that contains a lot of entities. Learning more about objects will help better define what can be done with the DOM entities, how they behave and why as well as how they can be used.
Lesson JavaScript Coding Exercise :
Select the page elements from the HTML file as JavaScript objects.
Create a global object that has a value for first, last, id and create several methods in the object.
Create a method in the object that uses the first and last name values from the object and combines them into a string, including the id and any value the is sent to the function as an argument.
Create a method within the object that can update the objects first and last name. Generate a random value for the object id. Return the combined current object property values
When the button is clicked update the value of the object first property
Output on the page and in the console the new string invoking the methods for the fullName from the object
Get the object entries as nested array values and create a new array using the Object.entries()
Get and create an array with the object keys Object.keys()
Get and create an array with the object values Object.values()
Using the in or condition check if a key is contained within the object
Loop through the properties names from an object and output them in the console
Check to see the datatype of the property value, if it's a string or number output it into the console otherwise output a warning into the console.
Object Construction with JavaScript coding
You can use functions to construct objects, using the arguments within the function.
Lesson JavaScript Coding Exercise :
Get the value from the input field, using it to create a new object for a person. This should set the first, last and using both of those create a full name for the object key values.
Add to the function default values in case the arguments do not have values.
Common JavaScript Array Methods to Update Array values
Arrays are also objects as a data type but they contain specific properties that allow the developer to interact with the contents of the array and its data.
arr.push(val); // add to array return the array length
arr.pop(); //remove last
arr.shift(); //remove first item
arr.unshift(val); //add to the front of array array length returned
arr.splice(1); // return array with all items after the index of 1
splice(start, deleteCount, val); //changes the contents of an array
slice(start, end); // returns a copy of a portion of an array into a new array
arr.slice(); //duplicate array as new array
arr.slice(5); // return array items from index 5
arr.slice(1,4); // return portion of array using slice
arr.toString(); // returns a string representation of the array items
arr.join(' - '); // returns a string representation of the array items using the argument value as a separator for the items in the array.
Lesson JavaScript Coding Exercise :
Setup HTML elements as JavaScript objects, add an onclick event to the button
Create 2 arrays, using concat join them to create a 3rd array, add one of the original arrays twice into the new array.
Try the different array methods push() pop() shift() and unshift() to update the data in the array.
Using splice() update the original array, create a new array from the array items that were spliced.
Using slice() create a new array from portions of the existing array
Convert an array into a string, also convert an array into a string using a dash as a separator.
Output the results into the console and on the web page.
Looping through Array contents forEach Methods and for loops for array data
Iterate through all the items in an array, selecting the items and their values. You can use the array length property in a for loop, or the array method of forEach(item,index,array) and return back the item values of the array.
Lesson JavaScript Coding Exercise :
Select all the HTML elements into the JavaScript code.
Using a for loop update the output element with new divs
Using document.querySelectorAll() select all the matching results for divs within a div
Using forEach loop through all the new divs, add a new property value of val, with a value of 0 to each new div.
Add a click event to each new div, that will output the element, the index value and the event.target element into the console. Update the val value of the element increment by 1. Check if the style color is red, if not set to red otherwise set to black. Output the number of times each div was clicked into the element text.
On the main button click, add a loop through all the arr items, using the for loop and output the array item value into the console.
Using forEach get all the array items and output them as a div into the page, listing the index plus one and the item value in the new element.
Array Methods for Items contained in the array JavaScript coding
Lesson JavaScript Coding Exercise :
Create an array with strings
Create an array populated with random numeric values 0-100
Using the array map() method create a new array with the value of the string array, and its index value as the new items
Using the map() method create a new array with all the numeric values from the numeric array multiplied by 2
Using filter() return only the results that have a value of larger than 50 from the numeric array values
Using reduce() add all the value together as a total return value from the numeric array values
Using every() check to see if all the values are less than 150
Using some() check to see if any of the values are less than 50
Output the new arrays into the console to inspect them
Using map intake the value of the input field, then multiply that by the number value of the items in the numeric array.
Using forEach() loop through all the contents of the new array from the previous step, output the results into the html of the page.
Array Methods for Sorting Array items using JavaScript Random Array
Get the random index value of the item from the array, and return the random item from the array.
How you can sort the arrays both in reverse and alphabetically.
Lesson JavaScript Coding Exercise :
Create an array with values, add to the array random numbers
When the button is clicked create a new array from the existing array filtering the data types with either numbers or strings
Using the array length, and math random() select a random index value for an array item.
When clicked, toggle either the sort() or reverse() methods to the array sorting in place.
Output the array as a string into the html of the page
Using sort() add a math random return of either positive or negative, which will randomize the array in place.
Wrap the randomizing of the array in a loop, testing 10 iterations to see the random array orders, output them to the html of the page
Using forEach() loop through all the array items and add them to the HTML
JavaScript Array Method Examples to find array items
JavaScript has several methods that can check for values contained within an array.
Lesson JavaScript Coding Exercise :
Create an array with some string and number values
Using the arr.includes() check if a value from the input field is in the array
Create a variable called html that can be built to return a string of the responses on the array methods. Using a ternary operator, create a response message if the term from the input is in the array or not.
Add to the html the response for includes
Create a check for the arr.indexOf() a value in the array, will return the index value or -1 if it's not found. Output the result to the HTML
Find the index value of the last item that matches, arr.lastIndexOf(), output the results into the HTML
Using find() return the first match for a number in the array, output the results to the HTML
Using find() return the first match for the condition checking for a == to the input value and the array item value. If none is found it will return undefined. Output the response result into the HTML
Using find() return the first matching result from the array of a value larger than 10. Notice it should also include and return the string.
JavaScript String Methods common functionality
Lesson JavaScript Coding Exercise :
Use trim() to remove whitespace from the input field value
When The button is clicked output string method results into the html for the input value
Output the length of the string
Check if it includes a value return the results as a message to the user
Slice out parts of the string using the index values
Output the string as toLowerCase() and toUpperCase()
Using replace - replace all the e’s in the string with x’s replace('e','x'), replace(/e/g,'x'), replaceAll('e','x')
Get the indexOf a string value, also get the lastIndexOf() the same string value
Using search get the index of the string search('e')
Create a function that can capitalize words in the string.
Interactive Word Scramble Game with JavaScript shuffle letters in strings
Lesson JavaScript Coding Exercise :
Create an array of words and phrases that you want to use for the game
Create a global game object that can hold the word that has been scrambled
create a function to start the game, called starter. Invoke the starter function.
Update the button text to say check answer
Update the input border and display properties to be solid black, and displayed as block
Clear the current value of the input field
Using Math random select a random item from the array of words
Create a function to scramble the words in the phrase called maker()
Within the maker() function convert the string into an array of each word. Create a holder array to use when you create the scrambled version of the words
Loop through all the words in the string, change the words to toLowerCase()
Split the letters of the word into a separate array. Using the sort() randomize the letters in the array. Using join() convert the array back into a string of randomly sorted letters from the word. Add it to the holding array
Return back the holder array, join the words back into a string.
Assign the scrambled words to the game's hidden value. Output the scrambled version of the phrase into the HTML page.
When the button is clicked check for the button text, if its new game then launch the starter() function to relaunch the game.
Convert the input to lowerCase. Compare the value with the hidden value of the selected string from the array. If there is a match the player solves it. Update the button text to the new game.
If it's incorrect, provide feedback to the player, asking them to try a new letter combination. It will continue to play until the correct solution is found.
LocalStorage with JavaScript JSON parse and Stringify of Objects
Lesson JavaScript Coding Exercise :
Try converting an array into a string, then parse it back to a usable array from the string. Do the same for the object. JSON.stringify(arr) JSON.parse(strArr)
When the HTML loads invoke a function that checks the local storage for a value using a key. If a value is returned then parse the string into an object. Output the contents of the object into the page.
Once the button is clicked, create an object that gets converted to a string, into localstorage.
Dynamic Interactive Web Pages with JavaScript
Introduction to JavaScript and the DOM how to create interactive web pages
The Document Object Model (DOM) is a programming interface that can be accessed with JavaScript to connect to web document contents. Web documents are based on HTML structure and can be viewed in a browser that renders the HTML or as HTML code. The HTML code is used to construct the DOM, which will represent the HTML source that the browser will use to construct the page. The DOM is used to create the web page, and selecting and updating the DOM representation of the HTML code allows JavaScript to make changes to the HTML without changing the HTML source code. The DOM is a standard object that has the HTML elements as objects, each with properties, methods and events.
Using JavaScript to connect to the DOM Object by selecting Page elements allows you to interact with them. Explore how to access page elements, manipulate content and properties of the page element. With JavaScript select and update contents of the element. DOM is a tree structure representing all the page elements and properties of those elements.
Using JavaScript you can change HTML elements, update attributes, remove and add HTML elements, add events.
Introduction to console.dir() document.querySelector() document.querySelectorAll() document.getElementtextContent() property value assignment.
document.querySelectorAll() returns a NodeList
document.getElementsByTagName() and document.getElementsByClassName() returns an HTMLCollection
Nodes in the DOM are referred to as all items, so everything is a node and every node is an object.
NodeList
Items can be selected by the index value that look like an array but are not
NodeList items can only be accessed with their index value
returns a static NodeList
You can access the childNodes of the list which is live
list with a length property which can be looped through
can contain any node type
HTMLCollection
Returns elements with ID in the collection, which can be selected using the ID from the list as well as index value.
HTMLCollection items can be accessed with a name, index or id value.
Live collection, does not include text nodes
item method can be used to access the elements from the list. eles.item(0)
list with a length property which can be looped through
contain any node Element
Lesson Coding Exercise :
Create an HTML file with page elements, include classes, and ids in the elements.
Select the elements using various methods .
Loop through a nodeList and an HTMLcollection output the elements and update the innerHTML of them. Observe the difference between the NodeList and HTMLCollection.
Creating and Deleting Elements with JavaScript Code
Lesson Coding Exercise :
Select HTMl elements to be used as parent elements for elements that will be created using document.createElement()
Create a function that can be used to generate new page elements. In the parameters add the element tag type, the parent and the html or contents of the element.
Using the function create an input element and a button element
Set the attribute of the input to be text and value of a string
Add an onclick event to the button, when clicked it will add a new item to the list
Create a list appended to the page. Using a for loop create several list items
Create a function that will add a list item to the unordered list. Update the inner text with a value, and add a style color for the text.
Within the function to create the list items, add an onclick event to the list items, that will select the list item and remove it from the parent. removeChild()
When the button is clicked add a function that will add a new list item, count the current number of list items. Add to the text of the new list item, the current input field value and the count of current list items in the DOM. Set a red font color in the new list item.
Check out the difference between append() prepend() appendChild() methods
Lists Move Elements from Parent to other element Items to Another List JavaScript Example
Lesson Coding Exercise :
update the parent styling to add CSS grid. document.body.style.display = 'grid' and set 2 column display of the children document.body.style.gridTemplateColumns = '1fr 1fr'
Create an array with string values
Create a global array which can be used to hold the ul lists
Select the divs from the page. Loop through each div and update the textContent to the list with index as a count.
Create an ul and add it into the div. Update the div with styling and append the ul to the parent div.
Add the new ul list to the uls global array
On the first run of the list append all the items from the array as new list items in the ul.
For the list items to make the HTML element editable add the attribute setAttribute('contenteditable', true)
Add a click event that toggles the class of the element with a class sel. Append the new list items to the parent ul
Add a button to the bottom of each list, add text content to the button.
When the button is clicked add an event to run a function called mover.
In the mover function, select the parent node of the button, using querySelect select the ul in the parent of the button.
Select all the elements that have a class of sel.
Using replaceChildren(...eles, ...parentEle.children) replace the children of the ul with the selected elements, add the existing elements from the parent back into the ul.
Remove the sel class from all the elements that have it.
AddEventListeners OnLoad and DOM loading events in JavaScript
Lesson Coding Exercise :
Add an event that gets invoked when the DOM content loads. Try window.onload , document.body.onload and document.addEventListener('DOMContentLoaded',()=>{})
Using addEventListener() add multiple events to the same element, try it also with onclick
Nest an element within its parent, using the useCapture set the boolean to true and check out the difference in order.
Add options to the event to only run once. { once: true }
Remove an event listener from an element removeEventListener
Form Select and Input fields values and creation of elements JavaScript Example
Lesson Coding Exercise :
To the main page element add a couple of text Nodes. Select them and update the text content of the text nodes.
Create an input text field set some common attributes to the input field
Create an input field that will be a number type, set the min and max attributes
Create an input field set it to date type
Create an input field set it to color type
Create and add a label, and a select element to the page. Add attributes to select multiple items in the select field
Create a number of options for the select field
Add a button that will list out all selected options from the select field into an unordered list.
Add radio buttons to the page with labels for their values
Add a button that will get the value of the selected radio button
List out all the input values other than the radio button values
DOM mouse and Keyboard events Page event listeners create Interactions
Lesson Coding Exercise :
Create a div and an unordered list to add content into
Add a button that will update the style background colors
Create an empty array to use as a holding array for page elements you want to update later
Create a function that can return a random hex value for the background colors
Create 10 divs, set the style properties of the elements, and include a random background color.
Add a click event that will set the body background color to match the background of the clicked element
Add mouseover, mouseleave, mouseout, mousedown, mouseup, and mouseenter events to all the divs. Create a function that will log the event trigger and a custom message into the output element and into the console.
Create 10 input elements, add event listeners onfocus, focusout, onchange to the elements. Update the style properties on the different events
Add a keyboard event to track the document. track the keys pressed.
Add a keyboard event onkeydown to the element input, if the enter key is pressed add the input field value to the unordered list as a list item
Create supporting functions to change the background of the body, random color generator, and a logging function that can output values into the console and into the output element on the page.
JavaScript RequestAnimationFrame smooth Animations within the DOM Ball bouncing example
The requestAnimationFrame() method can be used to create smooth animations within your web page elements. The browser then calls a specified function that can update an animation before the next repaint. The method takes a callback as an argument to be invoked before the repaint so that you can continue the animation function.
Lesson Coding Exercise :
Select the HTMl element that will be used as the parent container
Create an element div for displaying the score to the user, create a div that will be the ball in the Lesson Coding Exercise .
Update the style properties for the elements, round the ball, position needs to be relative or absolute to be able to move the element on the screen.
Create a global object to hold the x,y and the x direction and y direction. Include the speed and other values needed for the game.
Assign to a variable the requestAnimationFrame() then create a function that will run the movement.
In the animation frame function, check the pos of x and y ensure the values are within the boundaries of the parent, if not change the direction by multiplying the direction value by -1
Update the ball positions and apply the new position to the style left and top values.
Within the animation function, request the animation frame to keep the animation going.
Add an event for keydown values, if enter is pressed cancel the animation, or restart the animation.
Add an event listener on the ball, if clicked update the score and reset the position and color of the ball.
Create a score update function that will be invoked every time there is a score update.
Background Color Table Fun Create Table with JavaScript
This exercise will build an interactive table of colored cells that can be clicked to apply the cell background color to the page. In Addition several buttons to update the background colors of the table cells. The table will be dynamically generated using values for columns and rows. The application will also include 3 interactive buttons to update the page elements.
Button actions when clicked :
Add random background colors to all the td elements in the table
Get the color values from the elements in the row above, apply them to the following row creating a shifting down of the row colors to the below row. First row gets new random colors.
MoveLeft effect, when clicked will get the background color of the next element, and apply it to the element. The last element in the table will get a new background color randomly created.
Exercise :
Create a variable object for the number of rows and columns in the table.
Create a function to add the table to the page. The table function should create the main table element, loop through the rows and cols adding the tr and td page elements.
Generate and set the style of the cell width using the cols value, so that the cells take up the full width of the page.
As you add the td cells to the table, document.createElement('td') then add a text value of the number, then add some styling like border and text align.
Add an event listener to the td element, when clicked update the document.body background to the same as the table cell background color.
Create a function to generate random colors, Math.random().toString(16).slice(2,8)
Create a function to create buttons, add 3 buttons to the page.
Add an event listener to the first button, when clicked it should select all the page td cells from the main table. As it loops through the elements update the background to a random color
Create a second page button, this one will have an effect of moving the colors down one row. Select all the td cells from the main table. Create a holding array, as you loop through the cells, for the first row generates random values. Add these to the holding array. As you move through the second row, subtract the number of columns from the ind value of the td element. This will give you the value of the element that is in the row above. Get the background Color of the element above and add it to the holding array.
Once you complete the holding array it should have all the color values with one row shifted down, now loop through the holding array and apply the background colors to the matching td elements from the node list.
Create a third button. Once this button is clicked, loop through all the td elements in the main table. Update the background of the current element to the color of the element background to the right by one index value. For the last element td add a random background color.
Element Selector and Swap of Elements within the DOM JavaScript Code
This exercise is going to demonstrate how to select an element, and then move the element to a new part of the page. The elements can only exist in one place on the page, so when you have the element object selected you can then place it and move it to other parts of the webpage.
Exercise:
Select the main container element from the HTML
Using a loop create 20 spans within the main element
Apply and add styling to the spans. Add an event listener to the element.
On click run a function to get the event target element. Create a global object to hold the selected elements. Add a condition that checks if there is a value within the holding element. If there is then using insertBefore add the original element into the parent before the new selected element.
If the holding element does not exist, then select the event target element and add it as the holding element. Add some styling and an active class to the element. This will make it easier to select if needed and visual to the user so they know which element is the active one.
Add a condition that will check for the active class on elements, if found remove it from the element.
JavaScript Dynamic Modal from Data Object Create Modals with Code
This exercise will demonstrate how to create a modal from data, and dynamically add the buttons and the modals into your webpages. Each modal can have its own data that can create and customize them. The behaviors are the same so the code used can create the actions dynamically for each item in the data object.
Exercise :
Use the HTML code as the starter code for this project.
Select the main div from the page.
Create a data object that contains multiple items, each with a title, body, color and font color.
Loop through the items in the array, create page buttons for each. To each add a button on the page that can open the modal, once clicked the button should toggle the modal display settings, from none to block. This will hide and show the modal when the button is clicked.
Create a function to generate the modal called genModal. Return the main modal in that function, so that the element can be used. Add an event listener to the element that checks if the target event element is the same as the parent modal, then invoke the closer function with the modal object.
Within the genModal function pass the data into the function as an argument. This data can then be used to set the textContent and style of the modal elements.
Create a main parent that will be the overlay. Add the overlay class to the parent modal element.
Within the modal overlay parent, add a main modal container which will have the title, body.
Within the title create a text area element and a close button element.
Add an eventlistener to the close button element.
Page Clickers Create Dynamic Interactive Click Counters
This exercise will demonstrate how to attach custom property values into the element object. You can set a value just like within any object, and then access that value using its property name. This is ideal for tracking clickers that need to hold their own values and work independently of the other page elements and the other click values.
Coding to practice applying code to add event listeners on dynamic page elements. Create functions to clean up the code, and avoid repeat statements. Set element attributes, like type min and max. Create page elements with document.createElement() and then append it to the parent with append() prepend() or appendChild() Set element style properties with color, fontSize, backgroundColor, and content values textContent, innerHTML. Use forEach to loop through an array or nodeList.
Exercise :
Select the main page element that will be updated.
Create an input field and a button. Set the attributes to the input field so that it is a number type, and has a min of 1 and max of 20. Set a default value of 5 to the input.
Create a function to create elements, with parameters of the element tag name, and the parent that the element will be appended to.
Create an empty array to hold the main clicker elements, and the values of the clicks.
Add a button to generate a report of the clicker values. When the button is clicked, loop through the holding array, and add to the report the value of the clicker element with how many times it's been clicked.
On the button beside the input field, get the input value and create the number of clickers in the input value. Create a separate function to generate the clicker.
In the clicker maker function, create a main element container. Add a trackingValue property to the element, setting the value to 0. Add the new element into the holder array.
Create a div to hold the clicked value, a button to decrease, a button to increase and an input with a button to save the value from the input to the element clicked value.
Apply styling to the elements, create a function to add the attributes to each input field.
Create a function that will update the click values, using arguments for the input element, the text output element and the value of the clicker. Call it updater().
Add the event listeners to the clicker buttons, to increase and decrease. Send the values to the updater() function.
The 3rd button should take the value from the input and apply that value to the click value when pressed
Random Words Maker with JavaScript String Methods
This exercise will create a placeholder random word generator. There will be an input for the number of words to create and a button to add them to the page. The coding will focus on JavaScript String methods and how we can update strings, get a random letter from a string and how we can use random to randomize the content that is being output. Also will be using Math in order to add random content and structure the output to look like proper sentences.
String methods used in this lesson include, toUpperCase, slice, trim, substring
DOM elements will be created with JavaScript code, including how to create and select elements. How to add event listeners to the element. document.createElement() document.querySelector. Update the page elements with append() and prepend()
Exercise :
Select a main page element, create an input and button element. Add the new elements into the HTML page.
Add two strings, one containing vowels and the other common letters to use.
Add an onclick event to the button, once clicked invokes a function called makeWords() that passes the number of words to create using the input value. Also as one of the parameters include the element where the new text will be placed.
Create a main loop, that will loop the code for the number of words needed. Each iteration will create a new word to the string.
Create a random number for the letters of the word to be created. Then nest a new loop within the main loop, iterating the number of times randomly selected.
Create a random value that will randomize if a vowel is needed, or if a letter. Depending on the random result use either the letters or the vowel strings to select the next letter. Select the next letter randomly and add it to the word.
Add a condition to check if the word is the first one, if it is then capitalize the first letter in the word.
Randomize adding an end of the sentence, to capitalize the letter and add a period.
Using the complete words string, create a new page element and add the textContent value to the string of the generated words. Prepend the new element in the container.
Scrollbar scroll tracker Calculate the Scroll position on the page
This exercise is going to provide practice with updating style properties of page elements. Including style of textAlign, border, padding, position, width, backgroundColor, height, color, top, left, zIndex. We are also going to use values from the main HTML element, which is in the document as an object with the property name document.documentElement. The document.documentElement will return the root element of the document which is the HTML element. The scrollHeight, scrollTop, and clientHeight of the document.documentElement can be used to calculate the position of the current scroll on the document, and how much of the document is remaining. This can be used to get a percentage of the document that is currently scrolled to.
Exercise :
Select the main page element, add new divs into it. Create random heights of the divs so that you can use the scroll bar and the page content is larger than the area within the browser.
Create a main scrollbar container, and two divs, each nested within the parent.
Apply styling to the main scroll bar container, set a fixed position, and width of 100%.Add styling as needed.
Create the empty scroll indicator with a height and width of 100% This can be used as the blank area that the inner scroll bar will fill as the user scrolls down the page.
Add the inner scroll bar, set width to 0 and set a background color different from its parent
Using the window.onscroll event, calculate the position of the scroller. Get the top value of the current document in the browser. Using the document.documentElement.scrollTop which will change and be 0 if at the top. document.body.scrollTop will be 0 as it's the document top if your body is at the top of the web page.
The document.documentElement.scrollHeight will always be the total height of all the body contents. The document.documentElement.clientHeight is the visible area in the browser of the page.
Subtract the document.documentElement.scrollHeight - document.documentElement.clientHeight which will give a value of the total available height of the scrolling. Subtracting the clientHeight will set the height to 0 once the bottom of the page is reached.
Divide the total value off the top document.documentElement.scrollTop which will increase once the user scrolls down, with the total available body height. This will return a percentage, which then can be multiplied by 100 for a %
Use the percentage of page scrolled value to set the width of the scroll bar.
Exercise: Create a sortable list using drag and drop functionality.
Exercise: Write a function flattenArray that takes a deeply nested array and returns a flat array.
Exercise: Create a custom tooltip that appears when hovering over an element.
Exercise: Create a modal window that can be opened and closed using vanilla
Learn how to make your HTML and CSS code interactive and dynamic! JavaScript can interface with the Document Object Model and help make webpage elements come to life! Interact with web users via event listeners make your web pages respond to users and code.
Enroll now to get instant access to:
10+ hours of lessons
60 page downloadable workbook for Section 1 includes source code, tips, resources and challenges
27 page downloadable workbook for Section 2 includes source code, tips, resources and challenges
65 page downloadable workbook for Section 3 includes source code, tips, resources and challenges
Premium instructor support to help you learn
Lifetime access to course updates
10 NEW coding Projects added - 5.5hrs NEW video content
Background Color Table Fun Create Table with JavaScript
Element Selector and Swap of Elements within the DOM JavaScript Code
JavaScript Dynamic Modal from Data Object Create Modals with Code
Page Clickers Create Dynamic Interactive Click Counters
Random Words Maker with JavaScript String Methods
Scrollbar scroll tracker Calculate the Scroll position on the page
Math Quiz and Start and Stop Counters with JavaScript
Dynamic Interactive JavaScript DOM memory Game
Dynamic JavaScript Coin Flipping game DOM game.
JavaScript Battle Cards Game using Array methods
JavaScript holds the key to selecting and changing web page elements. The Document Object Model is a model of your HTML document represent within JavaScript as objects. Your browser builds the DOM and JavaScript can be used to connect to it selecting and accessing data contained within the DOM. All the web page elements are represented within the DOM. Elements are within the HTML page rendered out by the browser. JavaScript engine in the browser then create representations of the elements as JavaScript Objects
See how easy it is to select elements and make the interactive.
Explore JavaScript and how you can start coding JavaScript that will be able to interact with the Web page elements.
Section 1 Basic of Coding JavaScript
Covers all the fundamentals to code JavaScript - with examples and coding challenges in each lesson.
Explore how to get started with code, setup you developer environment. Create HTML files and connect your Javascript to the page elements.
JavaScript coding best practices with tips and resources. How to setup and use variables within your code. Different data types and how JavaScript manages the values. What functions are and how to use them in your code. DOM and how JavaScript code can use the DOM to connect, update and manipulate web page elements.
Lessons in the section include :
Introduction to how JavaScript works and how you can write JavaScript code
Getting started writing code how to code with Javascript
JavaScript Code Tips
How to use variables in JavaScript
JavaScript Dynamic Type Conversion
Variable naming Rules
Arrays and Objects in JavaScript
JavaScript Functions
JavaScript Document Object Model
DOM methods with JavaScript
Logic Conditions with JavaScript
Operators in JavaScript
Ternary Operator JavaScript
Math Random Values
JavaScript For and While Loops
JavaScript Objects
Object Construction with JavaScript
Common JavaScript Array Methods
Looping through Array contents
Array Methods for Items
Array Methods for Sort
JavaScript Array Method Examples
JavaScript String Methods
Word Scramble Game
JavaScript JSON parse and JSON.Stringify()
JavaScript is everywhere - all your favorite websites and also the ones you don’t like use JavaScript. Makes your web content come to life - JavaScript allows for interaction with content and makes things happen. JavaScript is the dynamic programming language that, when applied to an HTML document, can provide dynamic interactivity on websites. Used in all browsers it's the most popular coding language ever. Websites and web apps everywhere are using JavaScript. It runs directly in your browser and you can create html files with a text editor directly on your computer to run in your browser. Select the html file and open it with any browser.
Code is a set of instructions for what you want to happen. Example : When a new person comes to your website, ask their name. Showing a welcome message with their name would be an example of something you might ask JavaScript to do. The instructions for the code would be to provide the user an input area, get the input value of their name, then use that value to return a response. Select a page element and update the contents of the element with the welcome message including the value of the input for the user's name.
Getting started with JavaScript is easy: all you need is a modern Web browser. Create an index html file and open it in a browser Add JavaScript to the html either linking to a script file or JavaScript directly between the script tags in the HTML.
From an instructor with over 18 years of real world web development experience, here to help you learn how to use the DOM for your web projects. Ready to answer any questions you may have!
The DOM is like a doorway to access all of this functionality that is already there. JavaScript gives you the ability to open up that door and make amazing things happen on your website. This course covers only the JavaScript Document Object Model and prior JavaScript knowledge is a prerequisite to this course.
This course has everything you need to start creating your own interactive JavaScript code. This is a step by step guide explaining how and why JavaScript DOM is used.
Lesson JavaScript Coding Exercise :
Create an HTML file and a JS file.
Use the script tags to link to the JS file as the source file.
Using the document.write() add text to the webpage.
Using the document.write() add html formatted content to your webpage.
JavaScript Code Tips
Use Comments when possible single or multiple line
Indent using whitespace to make the code readable
Create code in a separate JS file and link to it from the HTML file
Use the console for debugging and to see values
How to use variables in JavaScript
Variables are one of the basic concepts of coding
Using const or let avoid using var
const and let are scope based
Parent scope vs local scope
Assign values to variables and reassign new updated values
Use of strings and numbers as values for variables
Dynamic type with JavaScript changing data type
Math and output from JavaScript directly
JavaScript Objects how to use Objects in code
One of JavaScript's data types is an object. These can be used to store various keyed collections and even more complex entities. The document is a giant object that contains a lot of entities. Learning more about objects will help better define what can be done with the DOM entities, how they behave and why as well as how they can be used.
JavaScript Document Object Model for interactive web pages
The Document Object Model (DOM) is an object that contains a data representation of the page elements. The DOM is structured in a tree like format, as objects that comprise the web page and content of the HTML web document. Document Object Model (DOM) is a programming interface for HTML documents, that is the logical structure of a page and how the page content can be accessed and manipulated. Bring your web pages to life with JavaScript and connect to the web page elements. Accessing the DOM you can create fully interactive content that responds to the user. DOM and JavaScript lets you create Dynamic web page content that can change without page refresh and present new elements and updated content to the user. Improve your web users experience with JavaScript and the DOM. What is the DOM Document Object Model How to select elements from your webpage with JavaScript Manipulate and change your page elements with JavaScript How to set styling attributes for elements Make them interactive with Event listeners DOM events and Page events with JavaScript How to create elements with code and add them to your webpage Moving elements and animation of elements.
DOM methods with JavaScript select HTML page elements
There are methods in the Document object that allow us to better select elements we want to manipulate with code. querySelector() and querySelectorAll() allow JavaScript to select page elements from the content within the document object.
JavaScript querySelectorAll Get Page Elements Select ALL. Use of querySelector and querySelectorAll to select matching page elements. Different selectors including tag, id, and class. Select page element, iterate contents of node list output and update page elements.
Logic Conditions with JavaScript if Statement Switch
Conditions can be used within code to apply logic, and run different actions based on the result of the condition. Depending on the value either True or False the code can run different blocks of code.
The if statement will check a condition, if true it runs the specified code. If false it does not run the code. Else provides an alternative if the condition is not true then else statement allows us to run a block of code on false if none of the previous conditions are true. You can also use the else if statement to check another condition with a separate block of code to be run if the previous condition came back as false.
Using the switch statement allows us to specify several alternatives checking to see if any of the conditions match and allow the corresponding code to be executed.
Math Random Values JavaScript get Random Numbers
JavaScript Math object contains various methods that can be used for math functionality, in addition it also contains the random method that creates random values in JavaScript. The Math.random() method returns a floating-point number in the range 0 (inclusive of 0) to less than 1 (not including 1). The random value can then be multiplied and rounded to the nearest whole number to include the randomized range of values desired by the developer.
Random values are ideal for games and to create unique custom experiences for web users.
JavaScript For, While Do While Loops Run blocks of code
Loops allow us to execute blocks of code a number of times, they also allow us to iterate through a list of items such as items in an array or other iterable list.
Loops will always require several parameters, such as a starting value, a condition to stop the loop and a way to move through the items to the next item in the loop. We can set up a simple for loop by setting a variable to use with a starting value, then applying a condition to continue the loop if the condition is true, and incrementing the value of the variable so that eventually the condition is no longer true.
JavaScript Objects how to use Objects in code
One of JavaScript's data types is an object. These can be used to store various keyed collections and even more complex entities. The document is a giant object that contains a lot of entities. Learning more about objects will help better define what can be done with the DOM entities, how they behave and why as well as how they can be used.
Arrays are also objects as a data type but they contain specific properties that allow the developer to interact with the contents of the array and its data.
arr.push(val); // add to array return the array length
arr.pop(); //remove last
arr.shift(); //remove first item
arr.unshift(val); //add to the front of array array length returned
arr.splice(1); // return array with all items after the index of 1
splice(start, deleteCount, val); //changes the contents of an array
slice(start, end); // returns a copy of a portion of an array into a new array
arr.slice(); //duplicate array as new array
arr.slice(5); // return array items from index 5
arr.slice(1,4); // return portion of array using slice
arr.toString(); // returns a string representation of the array items
arr.join(' - '); // returns a string representation of the array items using the argument value as a separator for the items in the array.
Introduction to how JavaScript works and how you can write JavaScript code
JavaScript is a core technology on the web alongside HTML CSS
JavaScript runs in the browser and gets rendered by the browser within the HTML page.
You can connect to HTML elements, using the HTML DOM which is a programming interface for JavaScript to add, update and remove HTML elements.
HTML elements can be accessed as objects that have properties, methods, and events.
Code is a set of instructions that tells the application in a language that can be understood by it, what to do.
JavaScript code is single threaded, which means that only one thing can happen at a time on the thread. Other requests get blocked until an operation completes and then those requests will run.
How to write code using a code editor or IDE.
How the elements from the HTML code are represented within the DOM tree structure, and that you can navigate from one to another.
What Devtools are and how you can use them
How you can use console log and console dir methods within the DevTools to view the document object and see the contents of the page elements in the DOM.
How to add JavaScript code within your HTML file and run the JavaScript code in your browser.
JavaScript commenting in the code and how to make your code more readable.
HTML is the markup language used to structure and provide meaning to the web content. CSS is the language used that contains the rules for styling the HTML content. JavaScript is the scripting language that allows you to create interactive and dynamic content within the web page.
You can do a lot with JavaScript such as store values, run blocks of code, apply logic with conditions and add events to your page elements. There is a lot you can do with JavaScript and the possibilities are endless.
APIs- are sets of prebuilt building blocks that allow developers to connect into and access these objects. Think of it like a control panel which JavaScript language lets you interact with.
Browser APIs allow access to the web page elements, and other data. You can access the API and do useful programming things. The DOM ( Document Object Model) API allows you to manipulate the HTML and CSS of the page.
Learn how to select HTML elements via tags, id, class and queryselection
traverse elements move between elements to properly select the ones you are looking for
Find out about nodes and how they work
Get data from the DOM about your page and elements
Update your element CSS via JavaScript
Add interactive listeners for page events
Explore how JavaScript objects work
Append and remove elements Dynamically
Useful code snippets
Source Code is included
Top resources and more
Everything is included for you to get started quickly
JavaScript is powerful, and the DOM really demonstrates this!
This course is designed to cover core aspects of JavaScript and cover the Document Object Model (DOM).
This course will demonstrate how to use the DOM and will help you develop skills how to manipulate the DOM within you website. JavaScript is one of the most in demand skills, and learning how to use JavaScript will help to separate you from the crowd. Want to know more, what are you waiting for take the first step. Join now to start learning how you too can create DYNAMIC and INTERACTIVE pages within your website today.
Please note that previous JavaScript and HTML experience is a requirement as the content of the course is to introduce the Document object model and how to connect JavaScript to the browser DOM. This course only covers JavaScript as it relates to the DOM and the scope is to cover Document Object related content