Replace class name for element without ID - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Style

Description

Replace class name for element without ID

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//from   ww  w  .  ja v  a 2  s . c om
function replaceClass()
         {
             var plusLinks = document.querySelectorAll('.my');
             var firstLink = plusLinks[0];
             firstLink.setAttribute('class', 'yourClassName');
         }
 replaceClass();
    }

      </script> 
   </head> 
   <body> 
      <div class="my">
         TEST TEST 
      </div>  
   </body>
</html>

Related Tutorials