Solved

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

Posted on 2014-10-21
4
108 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 40394948
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
ID: 40395313
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
ID: 40395328
$(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
ID: 40395567
Thanks!
0

Featured Post

Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
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 …
Suggested Courses

634 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