Solved

How do i onmouseover in a tr check to see if a key was pressed

Posted on 2014-10-21
4
101 Views
Last Modified: 2014-10-21
I have a large table with a lot of data. I'm trying to basically check to see if a letter was pressed while someone was hovering over a tr. What i'm trying to do is basically black out the whole screen except for the hovered over row when someone presses the letter f so that it can basically just focus on that row. Easier to see in the midst of a lot of data. Here's what i got so far. Don't know if i'm in the right direction, but it's not detecting me pressing the letter. Also, if they press f again or esc or click outside the row, i'd like it to go back to normal. Hope this makes sense. Thanks guys/girls!

$(function(){

  $('#report tr').on('mouseover',function(){
    $('#report tr').removeClass('sel');
    $(this).addClass('sel');

    $(this).keypress(function(event){
      if(event==70){
        alert('hello');
      }
    });

  });

});

Open in new window

0
Comment
Question by:engineroom
  • 2
  • 2
4 Comments
 
LVL 82

Expert Comment

by:leakim971
Comment Utility
Try this :
$(function(){
  // http://api.jquery.com/hover/
  $('#report tr').hover(function(){ // mouseover
      $('#report tr').removeClass('sel');
      $(this).addClass('sel');
  }, function() { // mouseout
      $(this).removeClass('sel');
  });

 $('#report tr').keypress(function(event){
      if( event==70 && $('#report tr.sel').length > 0 ) { // if a row have class sel it's on mouseover
        alert('hello'); // /!\ should loss focus /!\
      }
 });

});

Open in new window

0
 
LVL 3

Author Comment

by:engineroom
Comment Utility
That works, but doesn't seem to accomplish my goals. I need to basically add the .sel class to whatever row i'm currently hovered on when f is pressed. Hope this clears it up.
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
Comment Utility
$(function(){
  // http://api.jquery.com/hover/
  $('#report tr').hover(function(){ // mouseover
      $('#report tr').removeClass('hovered');
      $(this).addClass('hovered');
  }, function() { // mouseout
      $(this).removeClass('hovered');
  });

 $('#report tr').keypress(function(event){
      if( event==70 && $('#report tr.hovered').length > 0 ) { // if a row have class sel it's on mouseover
        alert('hello'); // /!\ should loss focus /!\
        $(this).addClass("sel");
      }
 });

});

Open in new window

0
 
LVL 3

Author Closing Comment

by:engineroom
Comment Utility
Thanks!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
In this Micro Tutorial viewers will learn how to create a CSS image sprite (In a later tutorial, viewers will learn how to use CSS and HTML to create a navigation menu using this sprite) Open a new Photoshop document with a width of (Icon width)x(N…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now