How to rewrite this javascript function with jQuery?
function setHeight() {
var iframes = parent.document.getElementsByClassName('targetIframe');
for(var i = 0; i < iframes.length; i++)
iframes[i].height = document['body'].offsetHeight;
}
A variation of this answer.
It's using the getElementsByClassName
function,which is not supported by IE.
How to rewrite it with jQuery?开发者_运维百科
It would look like this using .height()
:
function setHeight() {
$('.targetIframe', parent.document).height(document.body.offsetHeight);
}
Or for the literal height
attribute setting:
function setHeight() {
$('.targetIframe', parent.document).attr('height', document.body.offsetHeight);
}
function setHeight() {
var $iframes = $(parent.document).find('.targetIframe');
$iframes.each(function(i, elem) {
$(elem).height($(document.body).innerHeight());
});
}
Just replace first line with this:
var iframe = $('.targetIframe');
精彩评论