Citation in HTML and CSS

How can I reference a specific folder/file in my HTML code so that it encompasses the CSS, JavaScript, and HTML files?

Here's an example of the code I am working with:

<input onclick="setTimeout(function(){location.href='Darkmode';}, 500);" type="checkbox"/>
    <label></label>

Within my directory, I have a folder named Darkmode which contains files such as darkmode.html, css, and js.

I intend to use this folder as a subsite for my main website. When a user toggles the button on my main site, I want them to switch to Dark Mode.

The issue lies in how to properly reference all the Darkmode files simultaneously - including the HTML, CSS, and JS.

If I modify location.href='Darkmode'; to location.href='darkmode.html';, solely the HTML is targeted without incorporating the associated CSS and JavaScript. Is there a method to link to these various files collectively, such that the browser processes the CSS, JS, and HTML components of Dark Mode?

Answer №1

In the event that the HTML code varies, it is recommended to reference the html file darkmode.html and ensure that the appropriate CSS and JS files are linked within that file. However, if the design changes are minimal, it is considered a best practice to make alterations solely to the CSS. This can be achieved without modifying the actual page content by simply adjusting a single class in the body tag:

const btn = document.getElementById("darkmode")

btn.addEventListener("click", ()=>{
  document.body.classList.toggle("darkmode")
})
body.darkmode{
  background: #222;
  color: #fff;
}
<button id="darkmode">Click to switch light/dark</button>
<h1>This is my webpage</h1>
<p>Here is a paragraph</p>
<ul>
  <li>This</li>
  <li>is</li>
  <li>an</li>
  <li>unordered</li>
  <li>list</li>
</ul>

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

Can we display an express view in response to a WebSocket event?

My goal is to display an express view within a websocket event as shown below: socket.on('name', function () { //prompt the client to render a specific express view }); ...

Assign a class when a path is clicked using Leaflet.js

My goal is to apply a specific class to the clicked polygon by using the following code: function addClass() { function style(feature) { return { className: "active" }; } } function onEachFeature(feature, layer) { ...

Is it possible to include edit links to local files in an HTML report that I am creating?

Looking to enhance the readability of py.test reports that look like this: self = <test_testcenter_views.TestSiteViews testMethod=test_testcenter> def test_testcenter(self): "Test the tctr_update view." > r = self.client.get(&a ...

Creating a Pyraminx using triangular shapes

Attempting to create a Pyraminx, a tetrahedron made up of multiple triangles, through my coding. The approach I am taking may not be very precise. You can find my code here: https://codepen.io/jeffprod/pen/XWbBZLN. The issue I'm facing is manually in ...

Creating a responsive design for Bootstrap divs

I am trying to display 5 images in one row with 5 columns. I have used the following CSS for this layout: .col-half-offset { margin-left: 4.166666667% } This setup works well on the web, but on mobile devices, the layout does not di ...

Unable to loop through a list in JavaScript

<script type="text/javascript"> window.onload = function () { for (var i=0;i<@Model.listsinfo.Count;i++) { $('#work').append($('<div class="col-md-3" id="temp"><label for="tex ...

Mobile devices experiencing issues with rendering Dojo pie charts

After implementing this to display a pie chart in my mobile application, I encountered an issue. The chart functions correctly when tested on a browser simulator on my computer, but on the actual mobile device, it fails to render and instead shows a blank ...

What is the process to enable mandatory validation after a change in input in Angular 4?

Currently, I am working on a project using Angular 4. One of the tasks I need to achieve is validation. <input [(ngModel)]="someModel" required placeholder="some placeholder"/> The validation triggers immediately, but I want it to only trigger aft ...

What is the best way to create a dropdown menu within an iframe that appears on top of all other frames?

The code snippet below is from my frameset.jsp file: </head> <iframe width="100%" src="mail_frame.html"></iframe> <iframe width="105px" height="100%" src="sidenav.html" id="leftnav" name="leftnav" ></iframe> ...

Assistance required for JavaScript with Image and Hyperlinks

In the provided code snippet, I have included a javascript onclick function to the image tag. After clicking the image and then going back, the page remains on the current page rather than returning to the original page. Is there a way to prevent this beha ...

Using $_POST method to navigate within the same web page

<!doctype html> <html> <head> <meta charset="UTF-8"> <title>PHP links</title> <?php echo '<div style="background-color:#ccc; padding:20px">' . $_POST['message'] . '</div>'; ...

What is the best way to send a PHP variable in a WordPress AJAX request?

I have embedded a post (CPT) using a shortcode. Now, I want to filter the content of this embedded post using AJAX by sending its ID in the ajax call. The ID of the embedded post is retrieved from a shortcode like [documentlist listid="2126"]. $atts = sh ...

Using Roboto Typeface in Cascading Style Sheets

I am currently working on implementing the "Roboto" font in my Prestashop website. The design files I received are in .psd format, and the graphic designer used fonts "Roboto Medium" and "Roboto Regular". To clarify, if I want to use Roboto Normal, can I s ...

Tips for retrieving the chosen value from a dropdown list in HTML

I'm having an issue with exporting specific values from multiple HTML tables into an excel file. My goal is to only export the selected values from each table, with each table being on a separate tab in the excel file. Currently, when I export the ta ...

Utilizing AngularJS to Retrieve URL Parameters Within a Controller

I am attempting to retrieve URL parameters in my controller: Although I came across this example, I encountered an error that appears to be connected to the loading of necessary modules. app.controller('WidgetCtrl', ['$scope', '$ ...

Removing Files from an ASP.NET MVC 5 Website

Check Out the Code @using(Html.BeginForm("Edit", "Products", FormMethod.Post, new { enctype = "multipart/form-data" })) { @Html.AntiForgeryToken() < div class = "form-horizontal" > @Html.ValidationSummary(tr ...

What causes the difference in behavior between using setInterval() with a named function as an argument versus using an anonymous function?

I can't seem to figure out why using the function name in setInterval is causing issues, while passing an anonymous function works perfectly fine. In the example that's not working (it's logging NaN to the console and before the first call, ...

Retrieve the result of the Object match operation

Although I'm not an expert in JavaScript, please bear with me as I ask some basic questions. I've been struggling to find a suitable answer to my query. I am currently working on my first Node.js application, incorporating Extra Framework and So ...

Even when there is a change in value within the beforeEach hook, the original value remains unchanged and is used for dynamic tests

My current project setup: I am currently conducting dynamic tests on cypress where I receive a list of names from environment variables. The number of tests I run depends on the number of names in this list. What I aim to achieve: My main goal is to manip ...

`Vue JS table with Boostrap styling showcasing a loading indicator for busy state`

Issue: I need to show a loading icon while waiting for the table to load. https://i.sstatic.net/kRCbL.png I am utilizing Boostrap-vue JS, which is built on top of Bootstrap, and VueJS's "b-table" component to display approximately 3000 rows in a tabl ...