当前位置: 动力学知识库 > 问答 > 编程问答 >

Jquery - how to inject an event handler from embedded iframe into parent DOM elements

问题描述:

New to jquery and trying to get injection working. Any help appreciated.

I have an iframe embedded into a parent page. From within the iframe (where I instantiate jquery) I wish to inject an 'onmouseover' event handler to all DOM elements of class = "btn" in that parent page. All of these elements are in div levels within a top level container div with id = "contentWrapper"

Am assuming it'll be something like the following, but any tips really welcomed to point me in the right direction.

// am assuming I can see <div id='contentWrapper'> element in parent frame from within the iframe

// not sure where to place the 'btn' class reference.

$('contentWrapper').on('onmouseover', function(event){

// some activity here

});

网友答案:

try this

 parent.find('#contentWrapper .btn').on('onmouseover', function(event){ 
 // some activity here 
});
分享给朋友:
您可能感兴趣的文章:
随机阅读: