How can I get event bubbling to work when a div is clicked the first time?

I'm making a calendar. I want the user to be able to click anywhere inside a particular day (table cell) and something happens. There may be events for that day, which are contained inside a div within the table cell. If the user clicks on the div, then something else happens. I have managed to prevent event bubbling when the user clicks on `doSomethingElse()`, but it doesn't work the first time it is clicked. It only works on subsequent clicks, never on the first click. Why doesn't the cancelling of event bubbling work on the first click, and only works on all subsequent clicks? HTML:
Text
Javascript: function doSomethingElse() { $('.view').click(function(e){ e.cancelBubble = true; e.returnValue = false; if (e.stopPropagation) { e.stopPropagation(); } }); $('#myID').load('myFile.php'); } UPDATE: I put this on my page: Then, the `onclick="doSomethingElse()"` just contains the rest of my script. The problem is that `doSomethingElse()` has parameters, so it seems like I need to still have the following:
Text
It still only works on the 2nd, 3rd, ... clicks, but not the first.

以上就是How can I get event bubbling to work when a div is clicked the first time?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » jQuery 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏