Add new data attribute with javaScript - Javascript DOM

Javascript examples for DOM:Element setAttribute

Description

Add new data attribute with javaScript

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 w  w w.  j a v  a2  s . c  o  m
var el = document.getElementById("test");
el.setAttribute("data-transition" , "transform: translate3d(200px,100px,0)");
console.log(el.getAttribute("data-transition"));
    }

      </script> 
   </head> 
   <body> 
      <div id="test">
         bla bla
      </div>  
   </body>
</html>

Related Tutorials