0

EDIT: the following is pseudo code to represent real classes $('a:hover'); and $(a.subClass); that I want to reach by the means of 'this', being 'this' = <a>.

e.g. $(this:hover), $(this.subClass)

Tough that's not a correct syntax, you might get the idea. Let's say $(this); refers to an <a> element, and I would like to reach its :hover pseudo-class.

how would you do that?

I have a DOM element ' that I can reach in jquery as $('a'); or $(this);

That element has pseudo-classes (e.g. :hover) and sub-classes (e.g. .customClass) that I want to reach.

p.s. i have updated this question to make it more clear, thanks.

  • What information are you trying to get from the pseudo class? Maybe try backing up from this question and ask a broader question about what you're really trying to do. – treeface Feb 27 '12 at 21:29
  • http://stackoverflow.com/questions/1642072/jquery-css-hover – Veger Feb 27 '12 at 21:30

5 Answers5

1

Maybe you mean something like this?

$(this).filter(':hover')
Scott Evernden
  • 39,136
  • 15
  • 78
  • 84
1

That's what the jQuery .is() and .hasClass() methods are for. They return true or false if the element matches the given selector or has a specific class respectively.

You can't use .is() for hover though, have a look at attaching handler functions to hover state changes with .hover(function, function).

DarthJDG
  • 16,511
  • 11
  • 49
  • 56
0

You just cannot do that because no such selector exists.

I don't know what you are actually trying to do. But if you want to find out all the class names from an element then you can try this.

var classes = this.className.split(' ');
ShankarSangoli
  • 69,612
  • 13
  • 93
  • 124
0

The best way is to toggle a class for the hover and test for class

charlietfl
  • 170,828
  • 13
  • 121
  • 150
0

I think you are mixing CSS with JS.
The idea of JS is to make page interactive. If you want make something happen after 'hovering' an element, you should use event, for example hover event:

  $(this).hover(
   function(){alert('mouse in');}, 
   function(){alert('mouse out');}
  );

it might be the case that you need this information for if statement, sorry i can't use google right now :) conn problems :) i will update my answer if it is needed.

mkk
  • 7,583
  • 7
  • 46
  • 62