Hide ul with lost focus in jQuery

I am trying to hide the submenu (ul) elements when it has lost focus. My structure looks something like this.

            <div id="ActionDiv" style="border-color: #0099d4; width: 120px; height: 100%">
                <ul>
                    <li><a href="#"><span id="ActionHeader">Action &nbsp; <em>
                        <img src="images/zonebar-downarrow.png" alt="dropdown" />
                    </em></span></a>
                        <ul>
                            <li><a href="javascript:TriggerAction(1)">Send Email</a></li>
                            <li><a href="javascript:TriggerAction(1)">Invite to chat</a></li>
                            <li><a href="javascript:TriggerAction(1)">Consider For Opp</a></li>
                        </ul>
                    </li>
                </ul>
            </div>

In jQuery, I used the focusout event to handle lost focus.

$("#ActionDiv>ul>li>ul").focusout(function() {
            $("#ActionDiv>ul>li>ul").hide();
});

But the code above does not work. can anyone recommend a way to handle the lost focal event in ul.

+5
source share
3 answers

Try an event in jQuery .hover()

$("#ActionDiv>ul>li>ul").hover(function() {
       $("#ActionDiv>ul>li>ul").show();
   },
   function(){
       $("#ActionDiv>ul>li>ul").hide();
});
+5
source

, input ( textarea), ( , , !) focus blur ( , -, a ul li , , focusout ).

hover(), :

$('#elementID').hover(
function(){
   // mouse-over
},
function(){
  // mouse-out
});
+4

you seem to be looking for mouseout and mouseover events , not a focus event.

+3
source

All Articles