I want to get the data inside "opt_id".
And the same code works when i use selelct tag insted of datalist.
This is how my code looks like:
var get_data = document.getElementById("select_opt");
var dataIndex = get_data.options[get_data.selectedIndex].getAttribute("opt_id");
<input id="optio_lists" list="options" placeholder="Search...">
<datalist id="select_opt">
<option opt_id="0" label="Cricket">Cricket</option>
<option opt_id="1" label="Football">Football</option>
<option opt_id="2" label="Tennis">Tennis</option>
<option opt_id="3" label="Basketball">AKITA</option>
</datalist>
"select_op"should be"select_opt"opt_idis not a valid attribute. Use adata-*attribute for this ->data-opt_id