assign a variable to html element object - Javascript DOM

Javascript examples for DOM:Element setAttribute

Description

assign a variable to html element object

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(){/*  www . j  av a  2s  .c o  m*/
var elem = document.getElementById('questions');
console.log(elem.getAttribute('data'));
elem.setAttribute('data', 'newValue.html');
console.log(elem.getAttribute('data'));
    }

      </script> 
   </head> 
   <body> 
      <object id="questions" width="400" height="400" data="home.html">  
      </object>
   </body>
</html>

Related Tutorials