htmlタグの属性修正できない場合(親設定済み)、以下の例をとする
あず、既存属性を削除してから設定する。
$('iframe').each(function () {
$(this).removeAttr("height");
});
$("iframe").css({
'height': '550px',
'border': '2px solid'
});
●iframeの高さを自動的に調整してくれるスクリプト
(function (window, $) {
$(window).on("load", function () {
$('iframe.autoHeight').each(function () {
var D = $(this).get(0).contentWindow.document;
var innerHeight = Math.max(
D.body.scrollHeight, D.documentElement.scrollHeight,
D.body.offsetHeight, D.documentElement.offsetHeight,
D.body.clientHeight, D.documentElement.clientHeight
);
$(this).removeAttr("height").css('height', innerHeight + 'px');
});
});
})(window, jQuery);