You can use jQuery :contains()
pseudo-class selector to select based on content.
$("input[name=TypeList]").focusout(function(){
alert($(`#TypeList option:contains('${this.value}')`).data('value'));
});
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input id="s" name = "TypeList" list = "TypeList" placeholder = "Select Type"/>
<datalist id = "TypeList">
<option data="1" data-value="1">Internet Explore1</option>
<option data-value="4">Internet Explore4</option>
<option data-value="3">Internet Explore3</option>
<option data-value="2">Internet Explore2</option>
</datalist>
</body>
For an exact match, you have to use the filter()
method.
$("input[name=TypeList]").focusout(function() {
var val = this.value;
alert($('#TypeList option').filter(function() {
return val === this.value;
}).data('value'));
});
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input id="s" name="TypeList" list="TypeList" placeholder="Select Type" />
<datalist id="TypeList">
<option data="1" data-value="1">Internet Explore1</option>
<option data-value="4">Internet Explore4</option>
<option data-value="3">Internet Explore3</option>
<option data-value="2">Internet Explore2</option>
</datalist>
</body>
FYI : For getting data-*
value use jQuery data()
method.