开发者

How can I say this in jQuery?

I am tryng to say onClick of the link with class "myLink" show the div with the class "myDiv". And on focusOut hide the "myDiv" div. But my problem is with the focusOut part. Right now my code looks like this:

<div class="myDiv"></div>
<a href="#" class="myLink">Click Me</a>

$('.myDiv').hide();
$('.myLink').click(function(event) {
    $('.myDiv').show();
    event.preventDefault();
});
$('.myLink').focusout(function(event) {
    $('.myDiv').hide();
    event.preventDefault();
});

problem is, if the user clicks anywhere other than the "myLink" link it is considered focusOut. I don't want the div to hide if the user clicks within the div, I want it only to hide if the user clicks anywhere other than the link AND the div. H开发者_如何学运维ow to do this?


Have you tried binding to the div's focusout instead of the link's focusout?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜