0

Current question is extension of $(".someclass").is(":hover") works well for only single "someclass" instance

below jquery snippet works allready well for http://jsfiddle.net/4x661tt6/

$(document).ready(function() {
  $("body").mousedown(function() {
      if ($(".title").is(":hover") || $(".helper:hover").length ) return;
      $(".helpers").slideUp(); //slideToggle();
  });
  $(".title").mouseover(function() {
    $(".helpers").slideDown();
  });
});

my next problem is to make it run with http://jsfiddle.net/4x661tt6/1/ (recognize document mouse clicks excluding ".title" ".helper"), and in addition, to make each title trigger to slideDown() its owned childs differently...

Now, after source extension of another menu, hovering at any ".title" slidesDown() both instances, and background clicks stopped being recognized


edit: ive changed return line for

if ($(".title:hover").length || $(".helper:hover").length ) return; //is(":hover")

and it recognizes now more ".title" instances .... i coulded dig it earlier!

now only problem is to slideDown each ".title" differently, and Ill be at home

Community
  • 1
  • 1
s1w_
  • 133
  • 8
  • "This works here, now I want to make it run in there" isn't a proper problem description. Have you tried something to fix the issue or are you simply posting questions one after another...? – T J Nov 05 '14 at 15:29
  • Read the question before commenting. There are no absolute positioned elements. – Carlos Calla Nov 05 '14 at 15:38
  • I actually get a runtime error in the second example saying "Uncaught Error: Syntax error, unrecognized expression: unsupported pseudo: hover" – iCollect.it Ltd Nov 05 '14 at 15:39
  • I don't see any code with slideUp/Down.. what's your question again? You already fixed the hover problem. – Spokey Nov 05 '14 at 15:40
  • @TrueBlueAussie that was a useless side-note. I just said "Read the question before commenting" because obviously, you didn't read it. If you had read it you should have seen there is a `table`, some `div`s and no positioned elements. – Carlos Calla Nov 05 '14 at 15:52

1 Answers1

0

is(":hover") will only work on a single instance.

Try this bit:

$("body").mousedown(function() {
   var isHovered = !!$('.title, .helper').
                filter(function() { return $(this).is(":hover"); }).length;

   if (isHovered)
     return;
  alert( 'triggered' );
});

http://jsfiddle.net/wxfok6mv/1/

BReal14
  • 1,603
  • 1
  • 12
  • 35
  • I have allready solved that by `if ($(".title:hover").length || $(".helper:hover").length ) return;` but your solution is probably better. Now I need to do `$(".title").mouseover(..` to work for each ".title" differently /there isnt related jsfiddle snippet, but its unnecesary, i believe its common issue – s1w_ Nov 05 '14 at 16:13
  • Ok most part of question was solved, I can accept your answer. It was fast issue, sorry if you dont like easy ad hoc problems here; – s1w_ Nov 05 '14 at 16:21
  • I'm starting to believe that perhaps the method is a bit backwards for what you want to accomplish. Ie, why care about the body click if what you want to do is open a menu on hover? The markup provided in the fiddle doesn't really explain a hidden menu of sorts with sliding/toggling. I'd be happy to try further if you put up some markup of what you actually want to happen with the elements hidden until invoked/etc. – BReal14 Nov 05 '14 at 16:32
  • check http://siwego.net (top page), you will see my intention; its lightweight solution that works perfectly to my need – s1w_ Nov 05 '14 at 16:41