Is it possible to get element’s data in the way like in the example below
or – any similar way – except addEventListener
currently I’m getting error – e is not defined
Expecting result should be – lorem – ipsum – dolor – by typing inside the three inputs respectively
function on_input(e){
let a = e.target.data('x');
console.log(a);
}
<input type='text' class='inp' oninput="on_input()" data-x='lorem'>
<input type='text' class='inp' oninput="on_input()" data-x='ipsum'>
<input type='text' class='inp' oninput="on_input()" data-x='dolor'>
>Solution :
You should add the element as parameter into the function.
function on_input(elem){
let a = elem.getAttribute("data-x");
console.log(a);
}
<input type='text' class='inp' oninput="on_input(this)" data-x='lorem'>
<input type='text' class='inp' oninput="on_input(this)" data-x='ipsum'>
<input type='text' class='inp' oninput="on_input(this)" data-x='dolor'>