开发者

Trying to create a click method for a div, doesn't work in IE6?

I made a simple div:

<div id="foo"></div>

and I added a click method to it in jquery

$("#foo").click(wow);

function wow(){
  alert("Message");
}

This works fine in Firefox/others, but doesn't work in IE6/IE7? Why? Any specific resources on this?

Edit: The Div a开发者_StackOverflow社区lready exists in the dom, and the jQuery is run on ready, and it still doesn't work.


If you're creating the div dynamically, it won't work, and it won't work if that code is run before $(document).ready().

The solutions to both problems, respective, are to use jQuery's live mechanism if you're creating dynamic divs and to place all jQuery event binding in the document ready of the document.

Also make sure that your click handler function is defined before you assign it to the .click method.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜