Tips for switching the status of each item as I navigate the page with the tab key

I am facing an issue with my list of items that have hidden content appearing on hover. I want to achieve the same functionality while tabbing through my page, but currently, all hidden content appears at once.

Check out a live example of my code here

jQuery:

$('#top .item .content').hover(function (e) {
    $(this).children('.black-box').stop().slideToggle(300);
});

$('#top').on('keyup', function (e) {
    var keyCode = e.keyCode || e.which;
    var isTabbing = false;

    if (keyCode == 9) {
        if ($('.featured-content').find('*').is(':focus')) {
            if (!isTabbing) {
                isTabbing = true;
                $('.featured-content .item .content .black-box').stop().slideToggle(300);
            }
        }
    }
});

HTML:

<div id="top" class="featured-content">
  <div class="item">
      <h3>Tacos</h3>
      <div class="content">
          <img src="http://budapesttimes.hu/wp-content/themes/newsroom14/img/placeholder.png" alt="" class="image" />
          <div class="black-box">
              <div class="background"></div>
              <a href="#">I love tacos!</a>
          </div>
      </div>
      <div class="start-btn">Start Eating</div>
  </div>
  <div class="item">
      <h3>Pizza</h3>
      <div class="content">
          <img src="http://budapesttimes.hu/wp-content/themes/newsroom14/img/placeholder.png" alt="" class="image" />
          <div class="black-box">
              <div class="background"></div>
              <a href="#">And Pizzzzzzaaa! P-I-Z-Z-A!</a>
          </div>
      </div>
      <div class="start-btn">Keep Eating</div>
  </div>
  <div class="item">
      <h3>OMFG Naps</h3>
      <div class="content">
          <img src="http://budapesttimes.hu/wp-content/themes/newsroom14/img/placeholder.png" alt="" class="image" />
          <div class="black-box">
              <div class="background"></div>
              <a href="#">Because you just ate a ton of food! #foodcoma</a>
          </div>
      </div>
      <div class="start-btn">Go to sleep</div>
  </div>
</div>

Answer №1

One approach could be to utilize the focus and focus out functions to initiate your desired actions.

$('#header').on('focus', function(){
    // perform a specific action
});

$('#header').on('focusout', function(){
    // perform another specific action
});

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

IE11 experiencing issues with font loading

I need help troubleshooting why the fonts are not loading properly in the body section of my articles, specifically when viewed in Internet Explorer. Take a look at an example article here: I am fetching from this CSS file: , and I have included the nece ...

Troubleshooting: Resolving the Issue of Undefined Property Reading Error

I am currently working on a code snippet to render filtered data: const tasks = [{ task: "Complete homework", description: "Math and Science assignments." }, { task: "Walk the dog", description: "Take him for a stroll in the park." }, { ...

Adjusting the size of a textarea using jQuery

Below is my modified autogrow code for standard textarea, adjusted to bind on input propertychange in order to capture pastes. (function($) { $.fn.autogrow = function(options) { return this.filter('textarea').each(function() ...

Iterating through each ID in a table/cell using .NET MVC with the @

Whenever the table is loaded, I need to run a JavaScript function on each row for cell 4. This function will format the JSON string that is inserted into it. The current code I have only updates the first row/cell... I believe the issue may be related to ...

Retrieving all the information stored in the tables

I'm struggling with retrieving the content of my table cells. Some cells contain a hyphen (-) and if they do, I want to center the text. I'm facing difficulties with my jQuery code, particularly the if statement which always evaluates to false. ...

What could be causing my state not to change in Nextjs even though I followed the quick start guide for Easy Peasy?

I recently encountered an issue while trying to implement easy peasy for global state management in my nextjs app. The problem I faced was that the state would only update when I changed pages, which seemed odd. To better understand what was going on, I de ...

Activate the overflow feature within native-base cards

I have a unique design element on a website that showcases an image overflowing off a card. The image has a negative margin-top of -50, creating this effect. Now I'm trying to replicate this design in react-native using native-base components. Here i ...

Learn the best practices for sharing .env values from the main project component to various reusable npm installed components

In recent projects I've worked on using React and Vue.js, I have utilized .env variables to store API URLs for micro services and other configuration settings that are used throughout the root project. However, when it comes to child components insta ...

I could use some assistance with iterating through an array that is passed as a parameter to a function

Compute the product of parameter b and each element in the array. This code snippet currently only returns 25. This is because element a[0], which is "5", is being multiplied by argument b, which is also "5". The desired output should be ...

Updating Sencha list itemTpl on the fly

Is there a way to dynamically change the itemTpl in a Sencha list to adjust the visibility of a column based on certain conditions? Your assistance would be greatly appreciated. ...

last image in jscrollpane gallery getting cropped

I am currently working with a client on updating photos in a horizontal scroll gallery on their website. They have mentioned that the last few images always seem to have trouble loading properly. Sometimes they don't show up at all, or only partially ...

The container that utilizes the grid layout is compact and has a near-invisible height

grid-template: display; font-style: "Josefin Sans", sans-serif; size-of-text: 10px; element-height: 0px; spacing-bottom: 0px; spacing-left: 0px; spacing-right: 0px; spacing-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-up: 0 ...

Issue with PassportJs not forwarding users after successful authentication

I'm facing some challenges with implementing Passport for authentication. I have set up my signup strategy in the following way: passport.use('local_signup', new localStrategy({ usernameField: 'username', passwordField:&apo ...

Setting the timer: setTimeout function

As a beginner in jQuery, I am looking for the most efficient way to create a slideshow that automatically changes pictures and button statuses at set intervals. However, I want the auto image transitions to pause when a user clicks on any of the image butt ...

Send back alternate HTML content if the request is not made via AJAX

Last time I asked this question, I received several negative responses. This time, I will try to be more clear. Here is the structure of a website: Mainpage (Containing all resources and scripts) All Other pages (HTML only consists of elements of that ...

jQuery Algorithm for calculating totals

Here is an algorithm for formatting amounts using jQuery: Visit jsfiddle for the code However, there are some issues. For instance, if I enter 900.800,00 and then delete the "9", it still displays 00.800,00. How can this be resolved? I have fixed severa ...

Is there a way to convey a transition MUI property from a parent component to its child component in React?

My current setup involves a parent component with a button that triggers the opening of a snackBar from MUI (child component) upon click. To enhance the user experience, my teacher suggested adding a transition effect to the onClick event so that the snack ...

The MongoClient object does not possess the 'open' method

I recently started working on a project using Node.js, Express.js, and MongoDB. I've encountered some issues while trying to set up the database configuration. Below is a snippet of code from my index.js file: var http = require('http'), ...

Creating a secure authentication system with Parse for password recovery and website logins

Our organization has chosen to utilize a Parse backend for managing user accounts, and I am tasked with creating web pages for functionalities like password reset that will seamlessly integrate with our mobile applications. It has been some time since I ha ...

Ways to retrieve the content of a text box within a cell

Here is the code snippet I am currently working with: <tr val='question'> <td> <input style='width: 500px' type='text' placeholder='Q.Enter your question here for radio button? '> </ ...