I seem to be having trouble with the buttons not cycling through the div elements when clicked. Can anyone offer any insight into what might be

Apologies for the poorly worded question 3.5 years ago. I was just a naive 11-year-old back then.

I'm currently facing an issue with toggling between different div elements. The account feed div and the post page div have a display set to none in the CSS. The console is indicating difficulty understanding 'addEventListener' of null on line 22. Here is my JavaScript code for handling the display:

const accountFeed = document.getElementById('accountFeed')
const accountFeedButton = document.getElementById('accountFeedButton')

const homePage = document.getElementById('homePage')
const homePageButton = document.getElementById('defaultPageButton')

const postPage = document.getElementById('tweetPage')
const postPageButton = document.getElementById('posts-button')

const hide = (item) => {
    item.style.display = 'none'
}
const show = (item) => {
    item.style.display = 'inline'
}

accountFeedButton.addEventListener('click', () => {
    alert('accountFeedButton')
    hide(homePage)
    hide(postPage)
    show(accountFeed)
})
homePageButton.addEventListener('click', () => {
    alert('homePageButton')
    hide(accountFeed)
    hide(postPage)
    show(homePage)
})
postPageButton.addEventListener('click', () => {
    alert('postPageButton')
    hide(homePage)
    hide(accountFeed)
    show(postPage)
})

I have three separate divs, each in its own HTML file. The div containing the buttons isn't part of the home page div. I've included it in case there are any issues with the buttons. Here's the markup for the home page div:

<div id="wrapper">
    <button class="pageContent" id="defautPageButton">Home</button>
    <button class="pageContent" id="accountFeedButton">Account Feed</button>
    <button class="pageContent" id="posts-button">Post</button>
</div>
<div id="homePage" class="tabContent">
    <ul id="posts">
                             
    </ul>
</div>
<script src="page-loader.js"></script>

The account feed div:

<link rel="stylesheet" href="style.css">
<div id="accountFeed" class="tabContent">
    <p style="display: none">*</p>
    <ul id="posts">
         <li>Hello</li>
    </ul>
</div>

The post page div:

<link rel="stylesheet" href="style.css">
<div id="tweetPage" class="tabContent">
    <textarea class="post" rows="3"></textarea>
        <button id="post-a-comment">Post</button>
</div>
<script src="page-loader.js"></script>

Answer №1

Your button HTML contains a typo:

<button class="pageContent" id="defautPageButton">Home</button>

The correct id should be defaultPageButton. Making this change will resolve your issue.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Highcharts data setting failed due to a technical issue

I am facing an issue while trying to populate my highchart with data using a fetch function. The data is not being displayed or set in the chart element. Below is the fetch function I am using: fetch("data.csv") .then(response => response. ...

What is the best way to expand the web layout, including the header, navigation, and other elements, to the maximum

While browsing websites, I noticed an interesting design element that occurs when you zoom out in your browser. The header, navigation, content area, and footer all expand along with the layout. It seems like many popular websites, such as PC World, Micros ...

Navigating through website links while working locally on a localhost server can

After exclusively working on live domains or subdomains in the past, I recently experienced the benefits of working on localhost. Utilizing a Wamp server on my Windows machine, I store my project in C:/wamp64/www/[project_name]. I have always used relativ ...

What are the steps to delete data in angularjs?

I attempted to eliminate the data utilizing indexOf in AngularJS. Unfortunately, the remove function isn't functioning properly. Please guide me on identifying the mistake I may be making. JavaScript: var app = angular.module('myApp', []); ...

Is there a way to prevent one accordion pattern from automatically closing when another one is opened?

I'm currently working on a code that involves accordion patterns, and I've encountered an issue where opening and closing one accordion automatically closes another. I want all accordions to remain open until the user explicitly clicks to close t ...

Retrieving a channel using its unique ID and then sending a message directly into it

I am attempting to retrieve a channel by its ID and then send a message to it, but I keep encountering an error when running the code. ERROR: Error sending message to welcome channel.: TypeError: Cannot read properties of undefined (reading 'send&apos ...

Designing a web application with Angular2

As a newcomer to Angular2, I have recently started working on creating a simple hello world application. I have come across the concept of Modules and Components in Angular2. My main source of confusion lies in how to properly design an Angular2 applicat ...

Error in Angular Google Maps Component: Unable to access the 'nativeElement' property as it is undefined

I am currently working on creating an autofill input for AGM. Everything seems to be going smoothly, but I encountered an error when trying to integrate the component (app-agm-input) into my app.component.html: https://i.stack.imgur.com/mDtSA.png Here is ...

Failed to establish Modbus TCP connection

Currently, I am utilizing the "Panasonic FP7" master PLC along with their official software "FPWIN GR7" to monitor data flow on my PC. However, since the software lacks certain functions, I have decided to develop a solution using nodeJS. Below is the code ...

Can the server-side manipulate the browser's address bar?

Picture this scenario: a public display showcasing a browser viewing a web page. Can you send a GET or POST request from a mobile device to an HTTP server, causing an AJAX/pubsub/websocket JavaScript function to alter the displayed page on the screen? Per ...

Placing an image at the bottom right corner and layering it behind an svg element

I am currently attempting to position an image behind an angled SVG separator. Our goal is to achieve this look: https://i.sstatic.net/2YnsY.png However, the current display does not meet our expectations as illustrated here: https://i.sstatic.net/5Dssf ...

Guide to applying external styles to sub-components in Material UI while maintaining a cohesive common style throughout the entire component

I have a main page that consists of various smaller components. Within the page folder, there is the main page file, an external styles file, and folders for each individual sub-component - each of which has its own unique style. I'm struggling to fi ...

Struggling to superimpose my navigation bar onto the title page background

I'm currently learning HTML and CSS on my own while I am in university. My current project involves creating a one-page website, but I am having difficulty positioning the navigation bar over the title page. My goal is for the navigation bar to remai ...

jQuery is the key to unlocking the potential of Bootstrap 4 plugins. Discover the ingenious ways

When examining the code for registering plugins in jQuery within Bootstrap 4, I am having trouble understanding a few lines: https://github.com/twbs/bootstrap/blob/v4-dev/js/src/tooltip.js 1) Why did the author add the Constructor property to the Tooltip ...

Using an iframe with THREE.js and WebGlRenderer can result in the domElement's getBoundingClientRect method returning 0

I encountered an issue with my code: ... renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true }); renderer.setSize(WIDTH, HEIGHT); ... controls = new TrackballControls(camera, renderer.domElement); Strange behavior occurs when I r ...

Troubleshooting Fullcalendar Issues with Alternate Approaches in Vue JS

I'm currently using the Fullcalendar Vue plugin and I am trying to execute an action when clicking on a specific event. I have tried using Watch as well as running a Function, but both methods are limiting me from executing the desired action. Can you ...

Utilize Jquery to extract the functions from a PHP file

I'm a beginner with both jQuery and PHP. Currently, I have an HTML page where I need to utilize functions from a PHP file using jQuery, and then display the results in the HTML. My goal is to count the number of files in three different directories a ...

Leverage the power of lodash or es6 by creating a custom function that accepts an object containing deeply nested properties and outputs a new object containing only specific properties

I have a complex object with unnecessary properties and deeply nested values that I need to filter. My objective is to transform this initial object into a new object containing only the specific fields I require. Here's an illustration of the large ...

ControlsContainer - jQuery object for Flexslider

I recently tried to implement a flexslider with controls in a separate div using the controlsContainer option provided by flexslider. The setup consists of a left column containing the slider code (".flexslider-small"), a right column with text, and the c ...