Reputation: 21
for example if i write this code :
$(document).ready(function(){
$("div#i").click(function(){
alert("ok");
});
});
and the div element with the i id is not found in the page when load , so after i create it with some function ; and i click it , nothing happen , so how i can refresh the ready function in jquery ..
Upvotes: 2
Views: 12854
Reputation: 3044
Take that click event handler out of (document).ready and place it in the function that you've mentioned which creates the ID.
function someFunction()
{
//creates the id, then
$("div#i").click(function(){
alert("ok");
});
}
EDIT:
If this is just one example among many potential event handlers, then wrap them all in a single function, say, bindEvents()
and you can call that every time the page is 'dirtied' by an ID creation.
But the other commenters' approach of using .live() will probably be less to maintain, and it's "the JQuery way" if that's a concern for you.
Upvotes: 1