Reputation: 4345
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 already exists in the dom, and the jQuery is run on ready, and it still doesn't work.
Upvotes: 0
Views: 93
Reputation: 67862
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.
Upvotes: 1