user142830
user142830

Reputation:

jquery lost events

I would like to know if is there some jquery known behaviour that cause the lost of events handlers (in particular in iframes)?

I've a strange kind of problem. I've built a webapp composed of two iframe. First i load content in the first iframe. I add some event event handler using jquery to first iframe content dom. Everything works. On user input i load a page in the second iframe. Here too, I add some event handlers using jquery. Then the strange thing happens: jquery lost the event handlers in the first iframe. I said 'jquery lost' because if I add an event listener old way, it is still present.

Upvotes: 2

Views: 1319

Answers (2)

user142830
user142830

Reputation:

Problem solved.

The problem was caused accessing iframe2.contentWindow or iframe2.contentDocument on the second iframe, when the src of the second iframe was changed (1st time everything worked, from the 2nd onward caused problems) and the second frame was statically coded in the html.

To solve the problem I always remove the second iframe and recreate and append it to dom dynamically via javascript.

The problem occurs only on opera 9.7 embedded for mips (not sure for the exact version)

Upvotes: 2

MrHus
MrHus

Reputation: 33408

You might want to use live to bind events. This way when you add new elements with the same selector it will have the event binded to them.

$("p").live("click", function(){
    $(this).after("<p>Another paragraph!</p>");
});

Every subsequent p that is added to the page will have the event binded too.

Upvotes: 0

Related Questions