adaptive design - Javascript / Get an image element on page and but it in div (getElementByID) -


for banner, need put image displayed on same page. i'm bad developpement - so, use way - but, indeed, doesn't work...

<!doctype html> <html lang="fr"> <head>   <meta charset="utf-8">   <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">   <meta name="ad.size" content="width=300,height=600">   <title>stack</title>   <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>    <link href='https://fonts.googleapis.com/css?family=open+sans:400,700' rel='stylesheet' type='text/css'> </head> <body>   <a id="clickthroughbtn" href="javascript:window.open(window.clicktag)">   <div id="border">     <div id="container">       <div class="border2">         <div id="logo_bg"></div>         <div id="red_c" class="logo_element"></div>         <div id="rays" class="logo_element"></div>         <div class="logo"><img src="logo_fr.svg" alt="cofidis" /></div>         <div class="title">           test           <div id="adaptive">             <script>               function getimgs(){                 var adaptive = document.getelementsbyid('thumb0').img;                 adaptive[0].style.width="200px"; // taille de l'image                 adaptive[0].style.width="200px"; // hauteur               }             </script>           </div>         </div>       </div>     </div>     </a>     <img id="thumb0" src="http://gmz2.zarbi.be/avatars/m/1/1116.jpg?1404045273.jpg" /> </html> 

the important part -

<!-- adaptive --> <div id="adaptive">   <script>     function getimgs(){       var adaptive = document.getelementsbyid('thumb0').img;       adaptive[0].style.width="200px"; // taille de l'image       adaptive[0].style.width="200px"; // hauteur     }   </script> </div> <!-- adaptive --> 

thank ! ludovic

you need change this:

var adaptive = document.getelementsbyid('thumb0').img; adaptive[0].style.width="200px";                       // taille de l'image adaptive[0].style.width="200px";                       // hauteur 

to this:

var adaptive = document.getelementbyid('thumb0'); adaptive.style.width="200px";                         // set image width adaptive.style.height="200px";                        // set image height 

as there no such method getelementsbyid in document object.

also, getelementbyid returns single element. if need multiple objects, getelementsbyname, getelementsbyclassname , getelementsbytagname work you.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -