Reputation: 53
I am having trouble accessing multiple data params, passed to a rails link_to, in Jquery. I used to have the following code (embedded HAML):
= link_to "Update Setup/Teardown Times", '#', :class => 'update_setup_teardown_link', :data => @event.id
and I would access it in Jquery by writing the following:
a = $('.update_setup_teardown_link').attr('data');
But, if I had multiple data attributes as such:
= link_to "Update Setup/Teardown Times", '#', :class => 'update_setup_teardown_link', :data => {varId: @event.id, bool: true}
how would I be able to individually access these data attributes? Any and all help is appreciated. Cheers~
Upvotes: 0
Views: 50
Reputation: 454
varId = $('.update_setup_teardown_link').data('varId');
myBool = $('.update_setup_teardown_link').data('bool');
See: https://api.jquery.com/data/
OR
varId = $('.update_setup_teardown_link').attr('data-varId');
myBool = $('.update_setup_teardown_link').attr('data-bool');
See: https://api.jquery.com/attr/
Upvotes: 1