How do I use the data-attribute to pass a dynamically generated id from a rails app to jQuery? When I try, the value retus undefined unless I just send it to an alert box.
This code:
$(document).on "page:change", ->
$('#debug_link_id').click ->
alert $(this).data('dynamic_id)
Shows the dynamic_id in the alert box.
However, using the same selector, this code:
$(document).on "page:change", ->
jqVar = $(this).data('dynamic_id')
$('#link_id').click ->
alert jqVar
Shows "undefined" in the alert box. [using .attr('data-dynamic_id') gives the same results]
Kindly tell me:
- Why the first code works and the second doesn't
- If there is a better strategy for pulling dynamic id's into jQuery
