What is the best way to insert content into HTML elements based on the style sheet used?

Having two style-sheets that can be loaded by user choice presents an interesting challenge. The available style-sheets are named one.css and two.css. My goal is to dynamically change the content when the user switches themes. Here is what I have attempted so far:

function compareStrings ( str1, str2 ) {
    return ( ( str1 == str2 ) ? 0 : ( ( str1 > str2 ) ? 1 : -1 ) ; 
}

(function(){

          var href = $('link').attr('href');
          console.log(href); // check what style-sheet

           if(compareStrings(href,'one')==0)

             $("#p1").html('this is the content for one.css');  
             $("#p1").append("still for one.css"); 

           else if(compareStrings(href,'two')==0)
             $("#p1").html('this is the content for two.css');  
             $("#p1").append("still for two.css");     

          })();

The current approach does not seem to work as expected. Any suggestions on how to fix this issue?

Answer №1

Make sure to include the full href as "one.css" instead of just "one"

Here is a suggestion:

if(strcmp(href,'one.css')==0)

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

Exploring the wonders of retrieving JSON data in PHP through an Ajax request

A front-end developer is sending an array of data formatted as a JSON object using an Ajax call. The JSON object structure is shown below: { "name": " Test Name ", "image_url": "test URL", "include": [ "1" ], "dimension": [ null ], "media_type" ...

The WebSQL encountered an error stating `SQL execution is not permitted` while trying to chain promises

Despite the lengthy title, I couldn't think of a better one for my specific situation. If you have any suggestions, feel free to share! Essentially, I've outlined the issue I'm grappling with in a simplified version on this JSFiddle. In this ...

Developing pledges in AngularJS

I am currently working on implementing a promise in Angular using the $q service to retrieve an object from a web service. The unique aspect of this implementation is that if the object is already cached, it should be returned without making a call to the ...

"Exploring the process of unsubscribing or disposing of an interval observable based on a certain condition in Angular2 or

I am embarking on the journey into Rx and reactive programming, facing a situation that requires me to continuously monitor a hardware's status by sending a POST request to its REST API every 500ms. The goal is to stop the interval observable once the ...

Animate with Jquery sliding technique

Allow me to explain a situation that may seem unclear at first glance. I have implemented a jQuery script that animates a sliding box upon hover. $(function() { $('.toggler').hover(function() { $(this).find('div').slideTog ...

Retrieve the data value from a click event using the class identifier

The following code will display the correct class name, but not the correct data-validamount. It will only show: undefined. $(".prod_amount_add").click(function(){ var rowAmount = 0; var datavalid = $(this).attr('data-validamount'); ...

Could you offer assistance in resolving the error I am encountering with the collection.get() function?

I encountered an issue while trying to implement a database in my project. I imported 'collection' to use in my code. Here is the snippet: import { initializeApp } from "https://www.gstatic.com/firebasejs/9.0.2/firebase-app.js"; import ...

Error: Unexpected token "}" was not caught

While debugging my code in Google Chrome, I encountered a red text message: Uncaught SyntaxError: Unexpected token }. It's puzzling to me why and where this error is originating. Here is the snippet of code from the source console: var chart = $( ...

Unable to determine the length of an array in Vue.js due to property being undefined

Within my vue.js data structure, I have the following: data() { return { formData: new Form({ files:[], Count:5, .. } I am attempting to retrieve the length using the following code : <div class="image-input& ...

Getting the environment variable from Rails in your JavaScript: A guide

I am currently working on implementing a key system within my application. In the code I am using, there is logic that looks like this: $('.key-test-button').on('click', function(){ if ($('.key-test-input').val() === "MYK ...

Breaking down a large array in Node.js to initiate multiple API calls

I am currently faced with a challenge where I have a CSV file containing 21k records, with each record being a single alphanumeric word. I need to process these records by sending them to an API in JSON key-value pair format. The API can only accept 500 el ...

Styling an input button to look like a link in Firefox and Internet Explorer

I'm currently using CSS to give my input button the appearance of a link. Here's how I've styled it: input#linkLike { background: none; border: none; cursor: pointer; margin: 0; padding: 0; text-decoration: none; ...

Connecting a Vue js model data to a Select2 select box

Utilizing select2 to improve an html select element, I am facing challenges in binding the value of the select element to a Vue variable because Select2 appears to be causing interference. Is there an optimal approach to achieve this data binding and even ...

How can I add new objects to an array in MongoDB?

Currently, I am facing a challenge in my project which involves utilizing MongoDB as the database. Specifically, I am struggling with updating an array of objects within the schema outlined below: roundData : { playsArray : [ ...

Unveiling the Secrets: Scraping HTML Code from a Webpage Dynamically Using Selenium and Python

Learning Selenium has been quite challenging for me as I am just getting started. I have a total of 3 buttons on a webpage, and after each button click, my goal is to retrieve the entire HTML code of the page (I am comfortable using BeautifulSoup for any n ...

Menu with a full-width fluid input field using semantic-ui

I am trying to create a fixed top menu with an image on the left, an input to its right, and another input on the far right. My goal is to have the center input stretch to fill all remaining space between the image and the other input. Although I would no ...

The inline $Emit function is not generating the correct random number when using Math.random()

I've been diving into the concept of $emit event in Vue and came across this tutorial: . I tried implementing something similar using Vue2.js, but every time I click the button, it gives me a rounded number instead of a random number like in the guide ...

using JavaScript to strip away content following .jpg

var lochash = "#http://www.thepresidiumschool.com/news_image/102%20NRD_7420.jpg&lg=1&slide=0"; I am looking to eliminate or modify the content that comes after .jpg. ...

Discovered an issue with AngularJS involving ng-show and ng-if?

Upon my investigation, I have identified multiple issues with angularjs: <div ng-show="['[]']">this should be displayed but it is not working as expected</div> <div ng-show="[]">this should be displayed but it is not working as ...

Enhancing the understanding of JavaScript error messages

In my code, I am reading the contents of a file, expecting it to be JSON, parsing it, and printing out the result: 'use strict'; const fs = require('fs'); const Promise = require("bluebird"); Promise.promisifyAll(fs); const printFile ...