4

I've tried to trigger a hover event on a previous row in a table so I could get it's effect defined in CSS but it's not working. Basically what I have is 2 rows joined that need this border effect for mouseovers whenever either row moused over. What is a solution in jQuery for this?

jQuery

$("tr").hover(function() {
  $(this).prev().trigger('mouseover');
});

CSS

tr:hover .row-right {
  border-right: 10px solid #CCC;
}
2
  • Could you please add your HTML code aswell Commented Jan 21, 2012 at 14:12
  • Triggering the mouseover event using JavaScript has no relation to the CSS hover property. See Yaron Uilel's answer for an alternative solution. Commented Jan 21, 2012 at 14:21

1 Answer 1

1

jQuery

 $("tr").mouseover(function() {
    $(this).prev().addClass('hover');
 });
 $("tr").mouseout(function() {
    $(this).prev().removeClass('hover');
 });

CSS

 tr.hover .row-right {
    border-right: 10px solid #CCC;
  }

jsFiddle link for this: http://jsfiddle.net/vsApc/

Sign up to request clarification or add additional context in comments.

1 Comment

Can this be achieved by triggering some events on $(this).prev()? To avoid using hover class and use :hover instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.