I have been trying to get the values stored inside a data attribute called data-title, however JavaScript doesn't display the value I have stored inside it. Been trying to put the value inside alert for testing, but it doesn't work. The following is my piece of code. Thank you.
<select id='item_ID' onchange='changeValue();'>
<option data-title="Title 1">1</option>
<option data-title="Title 2">2</option>
<option data-title="Title 3">3</option>
<option data-title="Title 4">4</option>
</select>
<script type="text/javascript">
function changeValue(){
var option=document.getElementById('item_ID');
alert(option.getAttribute('data-title'));
}
</script>