The website lacks accessibility features such as a text size swapper, but the contrast swapper is not functioning properly

As I embark on my first website project that requires accessibility controls, I find myself in need of the ability to adjust text size and contrast settings. Specifically, I want to offer options for small, default, and large text sizes as well as normal, yellow on black, and black on yellow contrast settings. While I consider myself an average front-end developer, I don't often work with JavaScript or jQuery.

To address this requirement, I plan to define classes in the HTML "body" element to handle each case.

In pursuit of this goal, I have developed the following jQuery script:

// Accessibility 
// Check for cookies and set body class accordingly
if($.cookie("bodyclass-text")) {
      $("body").addClass($.cookie("bodyclass-text"));
    }
if($.cookie("bodyclass-contrast")) {
      $("body").addClass($.cookie("bodyclass-contrast"));
    }
// initialize the jquery code
 $(document).ready(function(){
  // add or remove classes to body as appropriate
  // return false keeps the browser from following the link's '#' target

  // Text size
  $("#defaultText").click(function(){
    $("body").removeClass("small-text");
    $("body").removeClass("large-text");
    $.cookie("bodyclass-text", null);
    return false;
  });
  $("#smallText").click(function(){
    $("body").removeClass("large-text");
    $("body").addClass("small-text");
    $.cookie("bodyclass-text", "small-text", { expires: 365, path: '/' });
    return false;
  });
  $("#largeText").click(function(){
    $("body").removeClass("small-text");
    $("body").addClass("large-text");
    $.cookie("bodyclass-text", "large-text", { expires: 365, path: '/' });
    return false;
  });

  // Contrast
  $("#defaultContrast").click(function(){
    $("body").removeClass("black-on-yellow");
    $("body").removeClass("yellow-on-black");
    $.cookie("bodyclass-contrast", null);
    return false;
  });
  $("#yellowOnBlack").click(function(){
    $("body").removeClass("black-on-yellow");
    $("body").addClass("yellow-on-black");
    $.cookie("bodyclass-contrast", "yellow-on-black", { expires: 365, path: '/' });
    return false;
  });
  $("#blackOnYellow").click(function(){
    $("body").removeClass("yellow-on-black");
    $("body").addClass("black-on-yellow");
    $.cookie("bodyclass-contrast", "black-on-yellow", { expires: 365, path: '/' });
    return false;
  });
});

While I have succeeded in implementing the text size adjustments, I am facing challenges with the contrast settings. It seems like a CSS issue because when I inspect the page using Firebug, the body classes are being correctly applied but the yellow on black and black on yellow contrasts are not working as expected. I even attempted to include larger font sizes in the CSS, which worked for adjusting the text size.

Here is an excerpt of my relevant CSS styles:

/* Accessibility options */
body {
    font-size: 1em;
    color: #777;
    background: #fff;
}

body.yellow-on-black !important{
    color: yellow;
    background: black;
    font-size: 3em;
}

body.black-on-yellow !important{
    color: black;
    background: yellow;
    font-size: 3em;
}


body.small-text {
  font-size: 0.8em;
}

body.large-text {
  font-size: 1.4em;
}

For reference, here is a snippet of my HTML structure:

<div id="defaultText"><a>Normal text</a></div>
<div id="smallText"><a>Smaller text</a></div>
<div id="largeText"><a>Larger text</a></div>
<p>
<div id="defaultContrast"><a>Default Contrast</a></div>
<div id="yellowOnBlack"><a>Yellow on Black</a></div>
<div id="blackOnYellow"><a>Black on Yellow</a></div>

If anyone has suggestions on how to resolve this issue, please feel free to contribute your insights.

You can access the test web page at this URL:

The accessibility options can be found at the bottom of the right column on the webpage.

Thank you in advance for your assistance!

Answer №1

Two instances of !important are incorrectly used in the CSS code. Only individual properties can have !important, so these rules will be excluded. It is recommended to remove !important from

body.yellow-on-black !important{

and

body.black-on-yellow !important{

and consider adding !important only to specific properties if absolutely necessary. This should generally be avoided unless you need to override existing CSS with !important that cannot be modified.

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

I am unable to switch my carousel to full-screen mode

I'm struggling to make the carousel fullscreen even though I've set the width to 100%. Bootstrap was used in this project. Any help would be appreciated. Thank you! <html> <head> <link href="homepage.cs ...

`CSS Toggle Smooth Transition Effect`

I am working on creating 2 CSS toggle buttons that currently have a fade in and out effect when clicked. I would like them to have a sliding animation from right to left instead. Below is the HTML, CSS, and a link to a fiddle containing my code. Thank yo ...

Issue with AJAX and Jquery auto form update functionality malfunctioning

On my form page, here is the code snippet: <form action="/register-process" method="post" id="form1"> <script type="text/javascript"> jQuery(document).ready(function($) { $(document).on('focusout', '#dateenglish', function ...

Struggling to Parse JSON Responses?

Utilizing AJAX/JQuery to communicate with a WCF service presents its own set of challenges. One common method is implementing .NET try/catch error-handling on the service-side to manage different scenarios, such as user timeout errors. Typically, the servi ...

Switch from monochrome to color when hovering inside a clipping mask

I have successfully mastered the technique of changing an image from grey to color on hover using CSS and JavaScript. However, I am curious about whether it is possible to achieve the same effect using a clipping mask. Attached is an image that illustrate ...

I am unable to retrieve images using the querySelector method

Trying to target all images using JavaScript, here is the code: HTML : <div class="container"> <img src="Coca.jpg" class="imgg"> <img src="Water.jpg" class="imgg"> <img src="Tree.jpg" class="imgg"> <img src="Alien.jpg" class=" ...

A single click causes the entire row of cards to extend seamlessly

The cards on this tab were generated using a loop and the data is sourced from a database. When I click on the "Show More" button, the entire visible column expands along with it. The expansion does not reveal the content immediately; instead, the content ...

Performing two API calls using Jquery to fetch distinct dynamic elements within two nested $.each loops

There's an API link that contains crucial data about phone brands. From this initial data, I have to create a second API call for each brand to gather more detailed information. For example, the first JSON file (urlphonebrands) lists 3 phone brands - ...

Using jQuery to swap out text

Here's what I'm trying to achieve: var newValue = $('.TwitterSpot').text().replace('#', 'Blah Blah'); $('.TwitterSpot').text(newValue); I believe this code should replace all instances of "#" with "Blah ...

Run JavaScript when ColdFusion page is being loaded

Within my ColdFusion page, I have incorporated multiple cfinclude template calls to bring in separate files. Before each cfinclude template call, I am seeking a way to update a javascript variable. I have attempted to achieve this by using: <script typ ...

What is the best way to use JavaScript to fill in missing images with alternative HTML content?

As a provider of a service that helps users find the location of pictures, I face a challenge due to the fact that the pictures are stored on another internal site. Some users may not have access to this site as my service offers additional information. Th ...

My toggleclass function seems to be malfunctioning

I am encountering a strange issue with my jQuery script. It seems to work initially when I toggle between classes, but then requires an extra click every time I want to repeat the process. The classes switch as expected at first, but subsequent toggles req ...

Enclosing values in JavaScript literals

I apologize for the inconvenience. I am unsure why it is not functioning properly. If I input <button type="button" onclick="document.getElementById("demo").innerHTML = Date()">click</button> the above code does not work. However, if I u ...

What is the best way to update the text on buttons once they've been clicked for a variety of buttons

I'm encountering an issue with multiple buttons where clicking on any button causes the text to change on the first button, rather than the one I actually clicked on. All buttons have the same id, and using different ids for each button seems impracti ...

Guide on retrieving JSON information within an array utilizing a loop function

Hey everyone, I'm facing an issue and I could really use some help. I'm new to working with ajax processing and I'm stuck on a problem. I have successfully retrieved ajax data and now I need to store it in an array. My goal is to populate a ...

Troubleshooting problems with background-image in CSS using Javascript

My latest project involves coding to assign background images to various classes using jQuery. The image files are named in a numerical order, such as 0bg.jpg, 1bg.jpg, 2bg.jpg, and so on. for (i=0; i < 8; i++) { $('.hpCarousel:eq('+i+' ...

Error: The function window.intlTelInput is not recognized within the ReactJS framework

I am currently learning ReactJS and encountering an issue when using jQuery with React JS for intlTelInput. I have installed npm jQuery and imported all the necessary code. Additionally, I have included all the required CSS and jQuery links in my index.htm ...

Pass a string to a function and receive a JSON response

I'm new to working with jquery and ajax. I have a function that retrieves data and I want to access it through ajax. My function: public JsonResult FillSubject(string GroupServiceID) { //string GSID = GroupServiceID.Substring(1, (GroupServiceID. ...

Easy steps for aligning text with shiny html

Looking at the code below, I was able to successfully align the bullet-point text in the popover when hovering over the information circle. However, I am still struggling to justify-align its header right above it, as seen in this image. When I remove the ...

unselect the button using jQuery

I want to trigger a popover when a variable exceeds a certain value, triggered by clicking a button: $(function () { $('[data-toggle="tooltip"]').tooltip({ trigger: 'manual', placement: 'top', titl ...