Created
January 3, 2018 12:54
-
-
Save joshuamschultz/66819826fc37104fad04df9ee405e357 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
You can use data- attributes to pass arbitrary values to a HTML element: | |
link_to service.company.name, # e.g. "ACME" | |
'#', | |
:class => 'specific_service', | |
:data => {:id => service.id} # e.g. 12345 | |
which will result in something like this: | |
<a href="#" class="specific_service" data-id="12345">ACME</a> | |
this can be retrieved inside the Javascript, e.g. with jQuery: | |
$('.specific_service').click(function() { | |
var id = $(this).data('id'); | |
// now do something with the id | |
}); | |
note that i used :class not :id because the element can occur multiple times. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment