Using setAttribute on a selected option - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Option

Description

Using setAttribute on a selected option

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  www. ja  v a 2s  .co m*/
document.getElementById('employee').addEventListener('change', function() {
    this.selectedOptions[0].setAttribute('data-dept', 'Employee');
});
    }

      </script> 
   </head> 
   <body> 
      <select name="employee" id="employee"> 
         <option>John</option> 
         <option>Anna</option> 
      </select>  
   </body>
</html>

Related Tutorials