getelementbyid - How to target all classes with javascript. No jQuery -
i writing responsive program keeps changing width of sertain elements, corresponding other elements have % based width. works fine. ran problem when wanted change images in side div big grand parent of images.
js:
var thebigone = document.getelementbyid('imgpresentation'); var demimages = document.getelementsbyclassname('presentatinthis'); fixtheresponsiveness = setinterval(fixthis,1000); function fixthis() { demimages.style.width = thebigone.offsetwidth+"px"; } fixtheresponsiveness();
html:
<div id="imgpresentation" class="imgpresentation"> <div id="slidethemimgpresentation" class="slidethemimgpresentation"> <img class="presentatinthis" src="img/billeder/xyachtvisit/xyachtbesoeg1.jpg"/> <img class="presentatinthis" src="img/billeder/xyachtvisit/xyachtbesoeg2.jpg"/> <img class="presentatinthis" src="img/billeder/xyachtvisit/xyachtbesoeg3.jpg"/> <img class="presentatinthis" src="img/billeder/xyachtvisit/xyachtbesoeg4.jpg"/> <img class="presentatinthis" src="img/billeder/xyachtvisit/xyachtbesoeg5.jpg"/> <img class="presentatinthis" src="img/billeder/xyachtvisit/xyachtbesoeg6.jpg"/> <img class="presentatinthis" src="img/billeder/xyachtvisit/xyachtbesoeg7.jpg"/> <img class="presentatinthis" src="img/billeder/xyachtvisit/xyachtbesoeg8.jpg"/> <img class="presentatinthis" src="img/billeder/xyachtvisit/xyachtbesoeg9.jpg"/> <img class="presentatinthis" src="img/billeder/xyachtvisit/xyachtbesoeg10.jpg"/> </div> </div>
it works if replace "class" "id" , "getelementsbyclassname" "getelementbyid" works on first img inside div.
i not wish use jquery, please not suggest $('.presentatinthis')
document.getelementsbyclassname
returns nodelist, means have loop on result access , set each node's style
var = demimages.length; while (i--) demimages[i].style.width = thebigone.offsetwidth+"px";
Comments
Post a Comment