jquery - DIV height can't be resized with JavaScript -
i want resize height of div element javascript.
from div, i'm reading height
<div class="pages" id="alles"> this div i'l want resize (this can more one)
<div class="content-block" name="maxhoehe"> this javascript code:
var sh = document.getelementbyid("alles").offsetheight; document.getelementsbyname("maxhoehe").style.height = sh-180 + "px"; in chrome, i'l following error:
uncaught typeerror: cannot set property 'height' of undefined i don't no why?
the document#getelementsbyname method returns collection of elements need first element index otherwise style property undefined( nodelist doesn't have style property ).
document.getelementsbyname("maxhoehe")[0].style.height = (sh - 180) + "px"; to update all, iterate on elements , update property.
var elements = document.getelementsbyname("maxhoehe"); // in latest browser use array.from(elements) [].slice.call(elements).foreach(function(ele){ ele.style.height = (sh - 180) + "px" });
Comments
Post a Comment