Install CSS class to <img> element - Javascript DOM

Javascript examples for DOM:Element className

Description

Install CSS class to <img> element

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <style id="compiled-css" type="text/css">

.resize {//w  ww.  j ava 2 s. c o m
   width: 200px;
   transition: width 1s ease;
   height: 50px;
}


      </style> 
      <script type="text/javascript">
    window.onload=function(){
var img = document.getElementById("myimg");
img.className = "resize";
    }

      </script> 
   </head> 
   <body> 
      <img src="http://placehold.it/50x50" alt="" id="myimg">  
   </body>
</html>

Related Tutorials