JS-151-API
  • JavaScript Library
  • 02-DOM-Manipulation
    • Overview
    • DOM Explained
    • Example Setup
    • Selecting Elements
    • Events
    • Complete Example
  • 03-API Fundamentals
    • 0-Getting Started
      • Welcome
    • 1-Intro-To-APIs
      • Intro
      • Client
      • Requests
      • JSON
      • API Endpoints
      • Server
      • Response
      • Statelessness
      • REST
    • 2-Asynchronous-Programming
      • Intro
      • Callbacks
      • Promises
      • Promises Continued
      • Chaining Promises
    • 3-Fetch
      • Fetch Intro
      • Star Wars
        • Star Wars API
        • Star Wars Setup
        • Star Wars JS
      • Random Photo
        • Unsplash
        • Unsplash Setup
        • Unsplash JS
    • 4-Apps
      • 01-New York Times
        • 00-App Intro
        • 01-HTML/CSS/API Key
        • 02-Variables
        • 03-Event Listeners
        • 04-fetchResults
          • 01-fetchResults()
          • 02-preventDefault()
          • 03-fetch() method
          • 04-Dates
        • 05-displayResults
          • 01-Logging JSON
          • 02-Working with JSON
          • 03-Link Display
          • 04-Results Navigation
          • 05-Results Update
          • 06-Keywords
          • 07-Images
        • 06-Pagination
          • 01-Pagination Intro
          • 02-Pagination Functions
        • 07-Next Steps
      • 02-YouTube
        • html
        • youtube.css
        • youtube.js
      • 03-GoogleMaps
        • Setup
        • HTML and CSS files
        • API Key
        • JS Setup
        • Adding Your Location
        • Listeners
        • Custom Options
Powered by GitBook
On this page
  • Adding the JavaScript
  • Test
  1. 02-DOM-Manipulation

Example Setup

PreviousDOM ExplainedNextSelecting Elements

Last updated 7 years ago

Let's start to add some HTML and JavaScript that would allow us to manipulate the DOM. Follow these steps:

  1. Open the 02-JavaScript-DOM-Manipulation folder in VS Code.

  2. Go into index.html.

  3. Let's create the code for a basic HTML page. Remember the VS Code shortcut to create an HTML template: enter a single exclamation point and you should see the auto-complete option popup.

  4. Hit the tab button and you should see it auto-fill a blank HTML template.

  5. Go ahead and just add a temporary Hello World in some tags inside the body.

    <body>
     <h1>Hello World</h1>
    </body>
  6. Run the app and make sure you can see it in the browser.

Adding the JavaScript

Instead of creating a separate JavaScript file, let's include it directly in the index.html file. Replicate the following layout in your file:

</head>
<body>
    <!-- All of our HTML code will go here -->
    <h1>Hello World</h1>

    <script type="text/javascript">
        /* All of our JavaScript code will go here */
        var x = 10;
        console.log(x);
    </script>
</body>
</html>

Test

Run the app again after adding the code above. When you run the app, you should see 10 in the console.

Exclamation
Template