0

I just realized that that function is not working, i tried to return a boolean with something like this

console.log($(selector).hover(function(){return true;})

but it returns an object with everything in it, what should a do to get a boolean variable?

adiga
  • 34,372
  • 9
  • 61
  • 83
Christian
  • 481
  • 1
  • 7
  • 24
  • You'd get a far better response if you describe your problem instead of the attempted solution. With regards to your question, there's not really an 'is hovered' selector, but I'm 100% certain there's a better way to achieve whatever you're trying to do without it – Rory McCrossan Dec 03 '19 at 15:47
  • Im trying to get a boolean variable if a div is hovered so i can compare it with another variable in an if() – Christian Dec 03 '19 at 15:49
  • already answered https://stackoverflow.com/questions/8010267/jquery-condition-check-ishover-not-working – Saitama Dec 03 '19 at 15:51
  • You don't need a variable to know if something is hovered - attach an `mouseover`/`mouseenter` event handler to it. Then you *know* it's hovered and you can work the other variable in the event handler. – Rory McCrossan Dec 03 '19 at 15:52
  • @RoryMcCrossan the thing is im nesting mouseover/mouseenter events, right now im working in the mouseleave one but I must compare if the user left the div – Christian Dec 03 '19 at 15:56
  • `.hover` is an event - you can't use it to "check if a div is currently hovered" - without using flags (via mouseover/enter) you can use `$(select).filter(":hover").length > 0` see link provided above: https://stackoverflow.com/a/16500667/2181514 – freedomn-m Dec 03 '19 at 15:56
  • Does this answer your question? [Jquery condition check is(':hover') not working](https://stackoverflow.com/questions/8010267/jquery-condition-check-ishover-not-working) – freedomn-m Dec 03 '19 at 15:57
  • @freedomn-m still getting the same error 'Error: Syntax error, unrecognized expression: unsupported pseudo: hover' – Christian Dec 03 '19 at 15:58
  • *"still getting the **same** error"* - can't see where you've mentioned this error before – freedomn-m Dec 03 '19 at 15:59
  • Works fine for me: https://jsfiddle.net/ectn60zf/ – freedomn-m Dec 03 '19 at 16:02
  • Please add all the relevant code (HTML, CSS and JS) to the question – Rory McCrossan Dec 03 '19 at 16:06

0 Answers0