开发者

How can I say this in jQuery?

开发者 https://www.devze.com 2023-01-23 16:10 出处:网络
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 l

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

精彩评论

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

关注公众号