What is the best way to connect individual buttons to a dynamic div that displays different content depending on the button clicked?

Hey there! I'm diving into the world of JavaScript and HTML, and I need some guidance on creating a menu that can toggle visibility of specific content in div(s) depending on which button (picture1-12) is clicked. My idea is to have one div that can display a string corresponding to the selected button. Hopefully, my explanation makes sense! Is there anyone out there who can assist me?

body{
background-color: #A50000;
}
#Container{
width: 90%; 
margin: 0 auto;
}
.CenterImage{
text-align: center;
}
.Menu{
float: left;
}
<!DOCTYPE html>
<html>
   <head>
      <link rel="stylesheet" type="text/css" href="style.css">
      <title>Test_Site</title>
   </head>
   <body>
      <div ID="Container">
         <div class="CenterImage">
            <img src="images\HeaderImage.jpg" alt="HeaderImage" width="100%">
         </div>
         <div class="Menu">
            <img src="images/Buttons/Picture1.png" alt="Button_1" style="position: absolute; top: 210px;"/>
            <img src="images/Buttons/Picture2.png" alt="Button_2" style="position: absolute; top: 320px;"/>
            <img src="images/Buttons/Picture3.png" alt="Button_3" style="position: absolute; top: 430px;"/>
            <img src="images/Buttons/Picture4.png" alt="Button_4" style="position: absolute; top: 540px;"/>
            <img src="images/Buttons/Picture5.png" alt="Button_5" style="position: absolute; top: 650px;"/>
            <img src="images/Buttons/Picture6.png" alt="Button_6" style="position: absolute; top: 760px;"/>
            <img src="images/Buttons/Picture7.png" alt="Button_7" style="position: absolute; top: 870px;"/>
            <img src="images/Buttons/Picture8.png" alt="Button_8" style="position: absolute; top: 980px;"/>
            <img src="images/Buttons/Picture9.png" alt="Button_9" style="position: absolute; top: 1090px;"/>
            <img src="images/Buttons/Picture10.png" alt="Button_10" style="position: absolute; top: 1200px;"/>
            <img src="images/Buttons/Picture11.png" alt="Button_11" style="position: absolute; top: 1310px;"/>
            <img src="images/Buttons/Picture12.png" alt="Button_12" style="position: absolute; top: 1420px;"/>
         </div>
      </div>
      </div>
   </body>
   </html>

Answer №1

To suit your specific needs, it's recommended that you tweak the IDs and styles accordingly. This solution appears to be what you're seeking.

<div style='display:none' id='CustomButton_1'>custom button 1 content</div>
<div style='display:none' id='CustomButton_12'>custom button 12 content</div>
<script type='text/javascript'>
 $(function() {
   $('.Nav img').click(function() {
     if ($(this).attr("alt") == 'CustomButton_1')
       $('#bluebox').html($('#CustomButton_1'.html()));
   });
 });
</script>

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

Route Separation with ExpressJS and Socket.IO

As I delve into the world of ExpressJS and Socket.IO, I find myself facing a puzzling situation. My routes are neatly organized in a separate file that I include from my app.js: var express = require('express') , db = require('./db&ap ...

flex child moves outside parent when available space shifts

My dilemma involves a flex container (A) containing two or more flex items stacked in a column. The top flex item (B) is a Bootstrap Collapse panel, while the bottom item (C) consists of two horizontal divs (D and E). The problem arises when the collapse p ...

Problem with locating elements using Selenium xpath

While using selenium and xpath, I encountered a peculiar issue. On a page, there are 25 <a> tags with nested <img/> tags. I am trying to retrieve all these elements using the findElements() method. Interestingly, upon inspecting the page source ...

How to enable the Copy to Clipboard feature for multiple buttons and transition from using an ID to a class identifier

Can someone please assist me? I have a copy to clipboard function that works well for IDs and a single button on my website. However, I need to modify it to work for multiple buttons and values with a class identifier. Unfortunately, I am unsure how to mak ...

What is the best way to ensure elements are rendered in Vue only when they are fully prepared?

Is there a way to delay the rendering of images in my list until all content is ready? I want everything, including text and classes, to finish loading before displaying anything. Even with v-cloak, it's not working! I'm having difficulty with t ...

What is the best way to incorporate Vuetify into a new application?

Recently, I developed a new app using Vue and I decided to integrate Vuetify as the framework. After executing the npm install vuetify --save command, Vuetify was added to the app successfully. However, when I tried to use it, the CSS button colors were no ...

jQuery selector unable to locate the specified class in the table row

After receiving an array of strings as a response from an SQL query, I am using JavaScript to dynamically add this data as rows to an HTML table: loadUsers: function() { . . . function displayUsersOnTable(response) { for(var i = ...

issues with the redirection functionality in the Play framework

I am currently working on an application that extracts data from Twitter profiles. I want to give the user the ability to select which parts of their profile should be used (for example, excluding tweets). To accomplish this, I plan to incorporate checkb ...

ReactJS state refuses to update

In my FreeCodeCamp leaderboard table, I have implemented functionality where clicking on the highlighted table header calls different URLs based on sorting criteria. The application either calls https://fcctop100.herokuapp.com/api/fccusers/top/recent or ht ...

How can I create a responsive input group with automatic width using Bootstrap 3.1?

I am having trouble with the layout of my two floating divs. The first div contains buttons and the second div contains an input-group. However, the input-group is moving down a line instead of utilizing the available space. Here is a link for reference: ...

Steps to transfer text from one input field to another by clicking a button using JavaScript

Hello, I am new to Javascript so please forgive me if my question seems silly. I have been tasked with creating a form containing two input fields and a button. When the button is clicked, the text entered in the first field should move to the second field ...

localStorage is functional on desktop devices; however, it does not work on mobile devices running iOS version 12

After developing a basic Todos application using React, I decided to introduce the use of localStorage to maintain data persistence between page reloads. Below is an overview of how I implemented it: loadStateFromLocalStorage() { for (let key in this.st ...

What is the process for sending a request and obtaining a response from a REST API using JavaScript?

I have a private server set up on my computer with a built-in REST API. The base URL for the API is: . I am now looking to develop a client application for this server using the API. To authenticate on the server, the API endpoint is baseurl/login with the ...

What could be the reason for Sequelize to completely replace the record when updating in a put request?

I've been attempting to implement an "edit" feature within my project, but I've hit a roadblock in the process. Here's a snippet of the put request code: export const updateEvent = (event, id) => (dispatch, getState) => { request ...

Some variables are not being properly tracked by Google Analytics

Within the document.ready() function of the primary GSP layout in my application, I have included the following code: var pageTitle = document.getElementsByTagName('title')[0].innerHTML; if('index' == 'list') { pageTitle ...

Arranging cards in a stack using VueJS

I am currently working with a small vue snippet. Originally, I had v-for and v-if conditions in the snippet, but due to issues reading the array, it is now hardcoded. The current setup produces three cards stacked on top of each other. I am exploring opti ...

Tips for accessing a variable value within a JavaScript function

I am currently facing an issue where I am unable to retrieve a variable from a JavaScript function and use it outside of the function. While I can successfully output the variable value inside the function, I am struggling to access it elsewhere in my sc ...

exploring div element(s) with jQuery

My HTML page contains multiple div elements in the body. I have also included buttons with associated click functions in jQuery to change the background-color of a div element based on the button pressed. However, I'm facing an issue at the 'term ...

Regular expression to validate the proper file naming convention: 1201_17-11-2015.zip

I am looking to verify if a specific file name follows the correct format. Here is the required format: first four numbers_two numbers-two numbers-4 numbers.zip To achieve this, I will need a regular expression. An example of a file name in JavaScript ...

Adjust the dimensions of the image carousel in Twitter Bootstrap

Here is the code that I am currently working with: <div class="col-sm-4"> <div class="card"> <div class="card-block"> <div class="col-sm-4"> <div id="carouselExampleIndi ...