开发者

How do I exclude certain clicks from stopPropagation() ? Jquery

I have a div #basket which is shown using the JQuery slideDown function.

To slide the div back up the use can click anywhere on the page.

$(document).click(function () {
  $("#basket:visible").stop(true, true).slideUp("slow");
});

Of course I don't want the div to be closed when a user clicks inside of it. So I use:

$("#basket").click(function (e) {

   e.stopPropagation();
});

Now the problem I'm having is that a form is contained in the div and this cancels ALL click functions within the div.

Is th开发者_开发知识库ere a way to close this div by clicking on the page without cancelling all clicks?


Have a look at event.target: http://api.jquery.com/event.target/

This will allow you to check which element the event is firing on within the click handler and act accordingly.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜