I set a data attribute for a user on a link like this
<input type="button" class="btn" data-user={"user": "<%= @user.name %>"} value="Start" id="game">
In the javascript function that listens for the click event, I did a console.log(e.target) and it printed the whole thing to the console.
<input type="button" class="btn" data-user={"user": "<%= @user.name %>"} value="Start" id="game">
If I do console.log(e) i.e. with no e.target, it logs the jquery event, but the data attribute is undefined
data: undefined
I'm trying to pull the username from the data attribute but don't know how to get it from this
<input type="button" class="btn" data-user={"user": "<%= @user.name %>"} value="Start" id="game">
and I don't know why data is undefined when I log just the event.
I'd be very grateful if you can assist me with this. Thanks in advance.
data-user="{'user': '<%= @user.name %>'}"ordata-user="<%= @user.name %>"console.log($(this).attr("data-user"))