简体   繁体   中英

how to get onclick event on the div inside the iframe using jquery/javascript?

HTML Structure

<iframe src="#" scrolling="no" id="gallery-frame">
<div class="gv_filmstrip">
<div class="gv_frame">
<div class="gv_thumbnail current">
<img src="images/grandstand-padang-right/1.jpg">
</div></div>
<div class="gv_frame">
<div class="gv_thumbnail">
<img src="images/grandstand-padang-right/2.jpg">
</div></div>
<div class="gv_frame">
<div class="gv_thumbnail">
<img src="images/grandstand-padang-right/3.jpg">
</div></div>
</div>
<div class="gv_panel"><img src="images/grandstand-padang-right/1.jpg"></div>
<div class="gv_panel"><img src="images/grandstand-padang-right/2.jpg"></div>
<div class="gv_panel"><img src="images/grandstand-padang-right/3.jpg"></div>
</iframe>

What i want is? I want to access the class gv_frame and put a onclick event on it .. in onclick event i need to find the width and height of img in gv_panel

Scripts i tried..

$("#gallery-frame").contents().find("gv_frame").click(function(){
alert("aaa"); // I am not getting the alert
});

2nd try

var width = $(".gv_panel img").width();
    var height = $(".gv_panel img").height();
    alert("width:"+width+" and height :"+height); // alert is null here

You have typos. Remove the contents() and add a . to your class selector.

$("#gallery-frame").find(".gv_frame").click(function(){
    alert("aaa"); // I am not getting the alert
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM