Is there a way of attaching data to elements in Rails like jQuery. For instance if you have
var element = $('element');
element.data('i', 'Hello world');
in jquery, you can retrieve that data later:
console.log(element.data('i));
will result in
Hello world
this way it stores the information in an obscure place resulting in a variable that isn't accessible from outside of jQuery directly.
In contrary, right now I'm only aware of appending HTML data attributes using Rails:
<%= content_tag(:div, "Something", data: { i: 'Hello world' }) %>
Which is equivalent of setting a .attr() in jQuery.
Setting HTML data attributes results in:
- visibility on the elements upon inspection
- cannot be objects
So essentially, what I'm trying to ask here is, can I append jQuery data set with Rails so it will be:
- accessible only from
.data() - not accessible from .attr() or anywhere else
- not publicly visible on the element upon inspection