Javascript examples for DOM HTML Element:Option
Using setAttribute on a selected option
<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>