Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save JamesPhillipsUK/5e9cba743518dcd8ee4e4640b1ec11ab to your computer and use it in GitHub Desktop.

Select an option

Save JamesPhillipsUK/5e9cba743518dcd8ee4e4640b1ec11ab to your computer and use it in GitHub Desktop.
Basic JavaScript Accessibility Tools using jQuery
<!DOCTYPE html>
<html>
<head>
<title>Accessibility Tools</title>
</head>
<body>
<!-- Here are the buttons we'll use -->
<button id="AccessibilityLarge" class="custom-class-to-style">Large Text</button> <!-- Button to increase text size -->
<button id="AccessibilityHigh" class="custom-class-to-style">High Contrast</button> <!-- Button to switch to high-contrast -->
<!-- Here are the scripts we'll call -->
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script src="./accessibility.js"></script>
</body>
</html>
//Here's our jQuery to power the buttons
//Increase normal text to 2 rem, and headings to 4 rem
$('#AccessibilityLarge').click(function ()
{
$('p,a,span,div').css({ 'font-size': '2rem' });
$('h1,h2,h3,h4,h5,h6').css({ 'font-size': '4rem' });
});
//Make text white, links yellow, the body black, and headings green
$('#AccessibilityHigh').click(function ()
{
$('p,span,div').css({ 'color': '#FFF' });
$('h1,h2,h3,h4,h5,h6').css({ 'color': '#0F0' });
$('a').css({ 'color': '#FF0' });
$('body').css({ 'background-color': '#000' });
});

Some Basic JS Accessibility Tools using jQuery

I've had this code lying around for a while now, and I only really use it on one website, because most people that need it have software that can do it for them. I thought other people may find it more useful than I do. So, feel free to use it.

The Code

  • accessibility.html, this contains the two buttons I use for increased accessibility. It also calls jQuery's CDN (but you can use locally hosted jQuery if you want), and it calls the accessibility.js script.
  • accessibility.js, this contains a jQuery event handler for each button, containing an anonymous function to handle the button's intended operation.

Get in touch

https://jamesphillipsuk.com/contact

Donate to my free software efforts

https://www.paypal.me/JamesPhillipsUK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment