I have an iframe, inside that iframe occurs dom elements additions by ajax.
With $(“iframe”).contents().find() y can access and work with .remove() .html() .click() without problems. But i can’t bind events for the new elements added by ajax with live();
my jquery code:
$("#iframe_id").contents().find("a .tittle").live('click',
function(e)
{
//stuff
}
);
But viewing the iframe in a new windows and workinkg with:
$("a .tittle").live('click',function(e)
{
//stuff
}
);
It works…
Any idea????
Thanks in advice.
won’t work, regardless of iframes.
live()can only be called on a direct selector, not one that comes from traversal methods likefind. Doc:This is in my opinion a poor, misleading bit of interface design, which is why I’d recommend using the
delegate()method in preference tolive()in all cases.Cross-document (into an iframe) event handling is also likely to be a problem. jQuery is not really designed for interacting with documents from code in different documents. I would recommend loading a copy of jQuery into each document, and handling events and DOM manipulation entirely within the code of that document.