Как получить значение атрибута width в теге img, находящемся в скрытом диве?
Дан к примеру вот такой скрытый див с вложенной внутрь картинкой:
<div id="div_id" style="display: none;"> <img id="img_id" src="i/sewing/combined/4001.png" width="990" height="388" /> </div> javascript код: document.getElementById('img_id').width или например на jquery: $('#img_id').attr('width') в ИЕ вернёт 0, хотя в теге прописано width="990". Кто-нибудь знает как получить значение атрибута width в ИЕ не делая див видимым? |
http://htmlbook.ru/css/display
прочитай что такое-display: none |
function getRealSize(element) {
var clone = element.cloneNode(true);
clone.style.position = "absolute";
clone.style.top = "-1000px";
clone.style.display = "";
document.body.appendChild(clone);
var sizes = {
height: clone.offsetHeight,
width: clone.offsetWidth
};
document.body.removeChild(clone);
return sizes;
}
alert( getRealSize(document.getElementById('img_id')).width );
|
Да, спасибо подошло.
|
А если так ? )))
<div id="div_id" style="display: none;">
<img id="img_id" src="http://javascript.ru/forum/images/ca_serenity/misc/logo.gif" width="990" height="388" />
</div>
<script type="text/javascript">
function getStyle(b, a) {
if (document.defaultView && document.defaultView.getComputedStyle) {
return document.defaultView.getComputedStyle(b, "")[a]
} else if (b.currentStyle) {
return b.currentStyle[a]
}
};
alert(getStyle( document.getElementById('img_id'),'width'))
</script>
|
| Часовой пояс GMT +3, время: 23:28. |