Mouse over fire key press event

Viewed 2266

I have the following html

 <div class="divcontainer" id="divcontainer1" data-element="1">
   <div class="innerdivcontainer hidden" id="innerdivcontainer1"></div>
 </div>
 <div class="divcontainer" id="divcontainer2" data-element="2">
   <div class="innerdivcontainer hidden" id="innerdivcontainer2"></div>
 </div>
 <div class="divcontainer" id="divcontainer3" data-element="3">
   <div class="innerdivcontainer hidden" id="innerdivcontainer3"></div>
 </div>

I want a function that fires when the mouse is over div container and a user begin to type on his keyboard. The function would change the class innerdivcontainer to not hidden only if the user is hovering over divcontainer and begins to type. I want to use .on because I have new elements loaded into the dom which should also work

I'm thinking something along these lines

 //check for mouse over event
   $('.divcontainer').on({
        mouseenter: function () {
     var data-element = $(this).attr('data-element').
               //check if user begins to type something with if statement
                   if(//code goes here){
                       $('innerdivcontainer'+data-element).show();

                     }

        }
   });

I don't know what to use to check for a key stroke on the keyboard

5 Answers
Related