jQuery how to select iframe? -
jQuery how to select iframe? -
i'm trying select closest iframe jquery. there lot of these windows so, i'd select nearest iframe. i'd expect closest() work, no luck.
javascript:
$(document).ready(function(){ var d = $(document); d.on('click', 'a.load_url', function() { var myframe = $(this).closest("iframe").attr("class"); alert("myframe: " + myframe); }); });
html:
<div id="window2"> <div class="navbar_top"> <span class="float_left"> <a href="#" class="load_url">click here</a> </span> </div> <div class="window_content" style="border: solid 2px blue; overflow:hidden;"> <iframe class="classy_iframe" src="http://mx7racing.com"> </iframe> </div> </div>
.closest
traverses dom (parents) , finds first matches.
to find iframe
you'll need this:
var myframe = $(this).closest("div.navbar_top").next('div.window_content').children('iframe').attr("class");
jquery iframe
Comments
Post a Comment