Incorporating Keyboard Features into Buttons

How can I toggle the page selectors in #pageList using a keyboard shortcut instead of clicking on the .togglePL button? I've tried looking up solutions online and asking questions here, but haven't found a working solution yet. Below is the code snippet for reference. Any help would be greatly appreciated. Thank you!

// Toggle Page List
$(document).ready(function() {
    $('.togglePL').click(function(e) {
        if ($('#pageList').width() == 40) {
            $('.textPL').show();
            $('#pageList').width(168);
            $('.togglePL').css({left:'192px', transform: 'none'});
             $('#pageList a').css({fontSize:'10pt'});
        }
        else {
            $('.textPL').hide();
            $('#pageList').width(40);
            $('.togglePL').css({left:'64px', transform: 'rotate(180deg)', transitionDuration:'0.3s'});
            $('#pageList a').css({fontSize:'14pt'});
        }
    });
});
/*
~ Copyright (c) Summit Learning Management System (made by students, for students). 2020.
*/

html > body {
height: 100%;
overflow: hidden;
margin: 0;
padding: 0;
font-family: "Trebuchet MS", sans-serif;
}

... (CSS Code continues)

<!doctype html>
<!--
~ Copyright (c) Summit Learning Management System (made by students, for students). 2020.
-->
<html lang="en-AU"><head>
<meta charset="UTF-8>
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0">
... (Head Content continues)

Answer №1

One way to achieve this is by checking the key event, specifically if the keycode is 80 and the altkey is pressed, then trigger a click event on the menu.

if (e.altKey && keyCode == 80) 

Here's the code snippet:

// Toggle Page List
$(document).ready(function() {
    $('.togglePL').click(function(e) {
        if ($('#pageList').width() == 40) {
            $('.textPL').show();
            $('#pageList').width(168);
            $('.togglePL').css({left:'192px', transform: 'none'});
             $('#pageList a').css({fontSize:'10pt'});
        }
        else {
            $('.textPL').hide();
            $('#pageList').width(40);
            $('.togglePL').css({left:'64px', transform: 'rotate(180deg)', transitionDuration:'0.3s'});
            $('#pageList a').css({fontSize:'14pt'});
        }
    });
});

$(document).on('keydown', function (e) {
        let keyCode = e.keyCode | e.which;
        if (e.altKey && keyCode == 80) {
           $('.togglePL').trigger('click')
        }
      })
/*
~ Copyright (c) Summit Learning Management System (made by students, for students). 2020.
*/

html > body {
height: 100%;
overflow: hidden;
margin: 0;
padding: 0;
font-family: "Trebuchet MS", sans-serif;
}

#wrapper {
display: flex;
flex-wrap: nowrap;
height: 100%;
min-height: 100vh;
overflow: hidden;
background: #555;
}
... (CSS styling omitted for brevity)
</body>
</html>

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

Learn how to perfectly align a draggable element onto a droppable image-map area with the help of jQuery!

In my HTML file, I have an image with an image-map and a draggable item (div element). Additionally, I've included jQuery to make the image/image-map droppable and the item draggable. When dragging the item over the image-map (droppable) area, the are ...

Is it a good idea to show a loading image for slow php/mysql results?

I need some help with my website that is powered by php/MySQL for querying and displaying results. The database has grown to over 40,000 records, causing the query to slow down. I am looking for an efficient way to show a loading image while the page loads ...

design facebook type box scroll bar

After extensively searching through various stackoverflow answers in an attempt to change the CSS for a Facebook likebox scrollbar, I have had no success. Below is the code that I am currently using: <div id="fb-root"></div> <script>(fun ...

Receiving an UNDEFINED INDEX error when trying to send data from an HTML form to a

I've created an HTML form that is styled using CSS for weekly work data entry. <form action="wwinsert.php" method="post"> <fieldset> <legend>Weekly Work</legend> <p><label class="lab1" for="StoreNumber">Store:</ ...

Updating the HTML class with JavaScript

My HTML class has two classes $(document).ready(function() { $(".container").hover(function() { $('.green').addClass('display-on'); }); $(".container").mouseleave(function() { $('.black&apos ...

Creating TypeScript modules for npm

I have been working on creating my first npm module. In the past, when I used TypeScript, I encountered a challenge where many modules lacked definition files. This led me to the decision of developing my module in TypeScript. However, I am struggling to ...

Display Bootstrap Modal using Typescript in Angular

Looking for some creative ideas here... My Angular site allows users to register for events by filling out a form. They can also register themselves and other people at the same time. https://i.sstatic.net/a44I7.png The current issue ~ when a user clicks ...

Tips for locating and clicking the 'Start' button in HTML using either find_element_by_xpath or the Selenium-Python API

Need help selecting the 'Start' button and clicking it in the HTML code below. I want to do this using the python-selenium library like so: driver.find_element_by_xpath('//div[contains(@class,"box enter")' ...

Angular JS allows you to easily remove the # symbol from a URL, improving the

I am encountering a problem with the "#" symbol in my angular js website's URL. I need to remove the # from the URL but the method provided isn't working and the site is not displaying properly. Can someone advise me on how to successfully remove ...

Determining the element type that was clicked using Angular

Is there a way in Angular to determine the type of element that was clicked? I have successfully implemented this functionality using jQuery, but I'm unsure how to achieve the same outcome in an Angular project. // Click action $(".contactlist").on(" ...

JavaScript code is functioning properly on Chrome and Internet Explorer, however, it may not be working on FireFox

Despite searching through the console, I am unable to find a solution to this issue. There are two images in play here - one is supposed to appear at specific coordinates while the other should follow the mouse cursor. However, the image intended to track ...

Update the value after verifying the element

I am trying to retrieve data from my database and update the values when an element is clicked (accepting user posts). The code I have written seems to work, but I encounter an error stating that props.actions is not a function when clicking on an element. ...

Achieving a sidebar that remains full height with CSS

Currently working on this page () where my aim is to create a sidebar that fills the entire height of the screen. The goal is for the sidebar, along with the black line on its right, to always reach the bottom of the viewport. JSFiddle Link Here's t ...

Loading React Components dynamically depending on user input

Looking to dynamically render different Components based on checkbox selections without unnecessary component imports. Using an Array with Component names (using numbers for example) to import each component based on the array values. Considered the foll ...

Obtain the Encoded Data

Unfortunately, I do not have control over domain.com. However, I am able to provide a redirect URL parameter like the one shown below: www.domain.com?retUrl=www.example.com%3Fparameter%3Dvalue Following the provision of retURL (www.example.com?parameter= ...

Can CSS interfere with the execution of the document ready function?

When I have a large CSS file on my page, will my document.ready execution wait for the CSS file to load? <!DOCTYPE html> <html> <head> <link rel="stylesheet" type="text/css" href="large-amount-file.css"> </head ...

Alert: The specified task "taskname" could not be located. To proceed with running grunt, consider using the --force option

My current task involves converting .css files to .sass files using the 'grunt-sass-convert' npm module. Here is the configuration in my 'Gruntfile.js': 'use strict'; module.exports = function(grunt){ grunt.loadNpmTasks( ...

I prefer children to have their own unique style, instead of inheriting their parent's CSS

I currently have a project structured in the following way: There is an index page with a full layout Separate PHP files that are included in the index page Bootstrap is used in the index page, however, in some of the separate PHP files I also use jqgri ...

revealing and concealing content using jquery

Just starting out in programming but eager to learn.. I'm looking to implement a show/hide feature for div elements using jQuery. I currently have two <div> elements, 1. <div class="div1"> 2. <div class="div2"> ----> set to hi ...

The MongoDB regex is failing to provide the expected outcome

I'm facing an issue with searching data in MongoDB. I have a table with approximately 5000 entries of data that need to be searched based on multiple columns with specific priority criteria. The first priorities for the search are symbol, name, co_nam ...