最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery click event for document but ignore a div - Stack Overflow

programmeradmin0浏览0评论

I have a online Slide Show I'm working on using jQuery. I have use $(document).click event to detect when a user clicks on the page to know when to show the next bullet point in the slide or to move to the next page.

The problem I'm running into is my job had me insert a comment box on the bottom of the page and when ever someone clicks on the comment box or the save comment button it also fires the click event for the page.

Is there a way I can have the click event for the entire page but ignore it when someone clicks in the DIV the Comment box/Save button are in?

I have a online Slide Show I'm working on using jQuery. I have use $(document).click event to detect when a user clicks on the page to know when to show the next bullet point in the slide or to move to the next page.

The problem I'm running into is my job had me insert a comment box on the bottom of the page and when ever someone clicks on the comment box or the save comment button it also fires the click event for the page.

Is there a way I can have the click event for the entire page but ignore it when someone clicks in the DIV the Comment box/Save button are in?

Share Improve this question edited Feb 10, 2009 at 17:36 Tom 15.9k5 gold badges50 silver badges63 bronze badges asked Feb 10, 2009 at 17:25 RoboDevRoboDev 4,15611 gold badges44 silver badges51 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 16

You will most likely need to stop the propagation of events in your Comments div using the event object's stopPropagation() method:

$('#comments').click(function(e) {
  e.stopPropagation();
});

if that doesn't work try using preventDefault():

e.preventDefault();
发布评论

评论列表(0)

  1. 暂无评论