The background color changes only on a specific page by selecting a color from the color picker

I created a webpage with a color picker that changes the color of the action bar. However, the action bar color only changes once and I want it to change on all other pages as well. Below is the code I used:

    <h4>Color Picker</h4>
<script>
function changeColor1(id1)
{
  document.getElementById(id1).style.color = "#00BCD4"; // forecolor
  document.getElementById(id1).style.backgroundColor = "#00BCD4"; // backcolor
}


function changeColor2(id2){

  document.getElementById(id2).style.color = "#D32F2F"; // forecolor
  document.getElementById(id2).style.backgroundColor = "#D32F2F"; // backcolor #009688
}

function changeColor3(id3){

  document.getElementById(id3).style.color = "#FFAB00"; // forecolor
  document.getElementById(id3).style.backgroundColor = "#FFAB00"; // backcolor
}

function changeColor4(id4){

  document.getElementById(id4).style.color ="#4CAF50"; // forecolor
  document.getElementById(id4).style.backgroundColor = "#4CAF50"; // backcolor
}  

</script>


<a href="#" onclick="changeColor1('myid'); return false;"><button type="button" class="btn btn-sq-xs btn-info"></button></a>

<a href="#" onclick="changeColor2('myid'); return false;"><button type="button" class="btn btn-sq-xs btn-danger"></button></a>

<a href="#" onclick="changeColor3('myid'); return false;"><button type="button" class="btn btn-sq-xs btn-warning"></button></a>

<a href="#" onclick="changeColor4('myid'); return false;"><button type="button" class="btn btn-sq-xs btn-success"></button></a>   
</div>
<a href="index.html"><h4> Logout</h4</a></p>

To enable dynamic color changing in all other pages when a color is clicked on the existing page, what steps should be taken?

Answer №1

Are the other pages different actual pages or are they dynamically loaded (such as through AJAX or hidden divs becoming visible)?

If you are physically navigating to other pages, your script must communicate with the server in order to make changes to those pages on the client side. One option is to use a cookie to store the color scheme and then have a script that retrieves the color scheme from the cookie and sets the action-bar color accordingly. This script should be executed each time a new page is initiated.

If the pages are dynamically generated, all you need to do is link the relevant elements to the trigger event.

The code snippet provided lacks context, making it difficult for me to offer a comprehensive analysis. I hope this information proves helpful!

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

Guide on converting a complex nested json into the jquery autocomplete format

How can I properly format a complex nested JSON for use with jQuery autocomplete? I have been attempting to map my custom JSON data to fit the required jQuery autocomplete format of label and value, but unfortunately, my list is returning as 'undefine ...

What is the best way to implement the verifyToken middleware into my Express router modules?

I am facing an issue with my express app setup, here is a glimpse: // index.js const express = require('express'); const app = express(); const userRoutes = require('./routes/userRoutes'); app.use('/user', userRoutes); const ...

JavaScript is having trouble properly concealing or revealing elements on the webpage

I am currently designing a web form for my wife, who works at an insurance agency. She needs a web-based form to collect information for processing insurance quotes. Without access to a server, I need to ensure that all the details inputted by the user can ...

How to Fix Owl Carousel Not Displaying in Bootstrap 5

I attempted to use Owl Carousel version 2.3.4 with a CDN, but it doesn't seem to be working. Here is my code, but the carousel is not displaying. Thank you. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3. ...

What's the connection between CSS and frameset?

Currently, I have an .html document with XHTML 1.0 Frameset doctype and the following code: <frameset rows="20%, 80%" border="1"> ... </frameset> Upon validating this code on W3C Validator, it gives me the error message: there is no a ...

The background image is tiled repeatedly across the screen

I am facing some challenges with setting a background image in my asp.net web application. The issue is that when I set the image to no-repeat, it displays according to its resolution of 640*480 and the rest of the page remains blank. However, if I don&a ...

Text that is aligned vertically and centered within a div container

I need help figuring out how to make a single line of text run vertically and stay centered within its container, both from left to right and top to bottom. Any suggestions on how to achieve this using CSS? ...

What steps can be taken to modify the style of a single button belonging to a broader group of elements?

Is there a way to hide the save button within a Vue Modal without affecting other buttons with the same class? .btn.btn-primary { display: none; } Simply targeting .btn-primary in the CSS affects all elements with that class, and adding .modal woul ...

Changing the click event using jQuery

My JavaScript snippet is displaying a widget on my page, but the links it generates are causing some issues. The links look like this: <a href="#" onclick="somefunction()">Link</a> When these links are clicked, the browser jumps to the top of ...

What is the best way for library creators to indicate to VSCode which suggested "import" is the correct one?

As a library creator, I have noticed that VSCode often suggests incorrect imports to users. For instance, VSCode typically suggests the following import: import useTranslation from 'next-translate/lib/esm/useTranslation' However, the correct im ...

What is the best way to position a button to the right side of the screen?

Is there a way to align a button to the right of a page? I attempted using text-align: right; and align-content: right; In addition, I want the button to utilize display: flex; #hideShow { display: flex; text-align: right; align-content: right; ...

What is the solution for resolving a pending promise in Node.js?

Within my initial file, pro.js: const newly = async function checkBalance(account, address){ const response = await fetch( `https://api-link`, { method: 'GET', headers: { 'api-key': .... ...

div container overflowing with numerous unordered list elements

I am having an issue with a div and ul in my HTML code. The height of the div is smaller than the combined height of all the li elements within it, so I have set overflow to auto in the CSS for the div. Here is an example of the HTML code: <div class= ...

The web font fails to display on different computers

Recently, I discovered that my website only displays the font "Open Sans" correctly on my personal computer. When I tried to access it from two other PCs, the font was not displaying as intended. Strangely, the font appears fine on smartphones. What could ...

I am attempting to create a basic animation using jQuery

Currently, I am working on animating a div. What I am aiming for is that when a user clicks a button, I want to hide one div and display another div that is the next child element. If you would like to see my progress so far, check out this fiddle. My in ...

Displaying various images within a bootstrap modal window

I'm facing an issue with my gallery. It contains small images, and when a user clicks on a thumbnail, a modal should open with the full-size image. The problem is that even though I have the full-size images stored in the "/uploads/" folder and the th ...

Hover over images for cool effects

Check out the code snippet I created on this link The current functionality enlarges images by 20 percent and overlaps into the table on hover. How can I enlarge both the image and table dimensions simultaneously? Below is the HTML code: <table borde ...

Arranging nested columns in a different order for smaller devices with Bootstrap 4

I am currently in the process of developing an e-commerce section, which includes an aside containing filters and a "main" section that should have 6 items displayed as individual cards. The challenge arises when viewing this on mobile screens, where the a ...

Turn off the footer button on materialize.css modal

I'm struggling to disable one of the modal footer buttons in materialize.css. I tried using disabled="disabled", but it doesn't seem to be working. You can see my example on jsfiddle. <a class="waves-effect waves-light btn modal-trigger" href ...

Is there a way to automatically remove the upload button after the file has been successfully uploaded?

I'm currently using blueimp and jquery UI to handle file uploads. My goal is to dynamically hide a specific button once a file is uploaded, and then display it again if the photo is removed. How can I achieve this functionality? https://i.stack.imgu ...