I am working with Jquery and php,I have text box and i am trying to pass "data attribute" (data-vals) value using jquery but i am getting "undefined" as response, Here is my code,Where i am wrong ?
<input type='text' name='postcmnt' class='postcmnt' value='" + str + "' data-vals='123' onkeydown='search(this)' />
<script>
function search(ele) {
if(event.key === 'Enter') {
var valss=$(this).data('vals');
alert('attribute value is '+valss);
}
}
</script>