I want to query a target for some data (that I set at runtime) in my event listener. I’m creating select elements at runtime like so:
<select id = "someid" >
<% list.each { |x| %>
<option> <%= x %></option>
<% } %>
</select>
In my event listener I would like to get not only “event.target.id”, but also “event.target.some_data_field_that_was_set_at_runtime”
Would I create a class in CSS that extends select and add my own data field, or something? Sorry, I don’t know HTML/CSS too well, if so could you give an example of how to write that class and use it? Thanks!
By “runtime” I assume you mean the standard: when your (looks like ASP) code runs on the server. On page-load in the browser is a different answer.
Also, the
optionvalue is not enough?Anyway, just have your code set a
relattribute for theselectelement. Or use HTML 5 data- Attributes.For Example: