Menu
Coddy logo textTech

Close Functionality

Lesson 12 of 13 in Coddy's Sidebar | Front-end Project course.

Now that the styling is done, let's add the click functionality!

challenge icon

Challenge

Easy

In the javascript module, target the id #closeSidebarBtn, and after clicking on it, set the right property of the 'sidebar' class to -250px.

Try it yourself

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="styles.css">
  <title>Mobile Sidebar</title>
</head>
<body>
  <button id="openSidebarBtn">Open</button>
  <div id="sidebar" class="sidebar">
    <button id="closeSidebarBtn">Close</button>
    <!-- Your sidebar content goes here -->
    <p>Home</p>
    <p>About</p>
    <p>Services</p>
    <p>Contact</p>
  </div>
  <script src="script.js"></script>
</body>
</html>

All lessons in Sidebar | Front-end Project