Note that there are some explanatory texts on larger screens.

plurals
  1. POChanging getElementById to getElementsByClassName
    primarykey
    data
    text
    <p>I am sure is a common problem in JS, i have created resizing function using JS, initially this function was only going to be used on one item of my site, however now i have chosen to use it on multiple items. My JS function currently uses <code>document.getElementById(id);</code> however i want to change this so it looks out for the class name <code>.resize</code>. How can this be done? Below is a snippet of my JS </p> <pre><code>function ebi(id){ return document.getElementById(id); } if(ebi('resize') .complete==true){ iscale(ebi('')); } ebi('resize') .onload=function(){iscale(this); } function iscale(o){ //alert(o.width); var sar=o.width/o.height; var tar=1,tiw,tih,xoff,yoff; if(o.width&lt;=425&amp;&amp;o.height&lt;=467){ tiw=o.width; tih=o.height; }else if(tar&gt;sar){ tiw=425*sar; tih=467; } else{ tiw=425; tih=467/sar; } xoff=(680-tiw)&gt;&gt;1; yoff=(209-tih)&gt;&gt;1; //alert(xoff); o.width=tiw;o.height=tih; o.style.top=yoff+"px"; o.style.left=xoff+"px"; } function $(id){return document.getElementById(id);} </code></pre> <p>html</p> <pre><code> &lt;section id="homeSlide" class="shadow"&gt; &lt;img id="resize"class='opaque' src="http://www.colette.fr/media/push/pony_01239.jpg" /&gt; &lt;img id="resize" src="http://www.colette.fr/media/push/EGIFT_01234.jpg" /&gt; &lt;img id="resize" src="http://www.colette.fr/media/push/swa_mmm_001255.jpg" /&gt; &lt;/section&gt; </code></pre> <p>At the moment the resize function only works for the first image, however the other images do not resize. Before anyone attacks me about web standards the <code>id</code>'s in the img tags were just to test the function. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload