javascript - Event not executing inside the iframe -
i adding content in iframe dynamically , content binded event using .live() function :
<body> <div id="container"> <iframe id="if" src="something"></iframe> </div> <script> /* binding event */ $(document).ready(function() { $("p").live("mouseover", function() { /* */ }); }); /* appending content */ $("#if").contents().find("#someid").append("<p></p>"); </script> </body> the p tag added event not executed on mouseover. whats problem?
note : can`t add binding event script inside iframe.
your live binding main document not iframe. did try following?
with jquery 1.4 , above use jquery delegate:
$("#if").ready(function() { $("#if").contents().delegate("p", "mouseover", function() { // }); }); with jquery 1.7 , above use jquery on:
$("#if").ready(function() { $("#if").contents().on("mouseover", "p", function() { // }); }); also see example delegate() or example on(): after "mouseevent loaded" alert hover cloud image.
p.s.: target <p> within iframe. iframe parsed if not violation of browser's cross-site policy.
Comments
Post a Comment