jquery - Creating custom data attribute in Rails image_tag -
i trying add custom data attribute rails image_tag allow jquery function.
first, starting image_tag so:
<%= image_tag("randomv1.png", class: "icon js-icon") %>
second, jquery, need image_tag trigger event, , want include data attribute 1 using button here:
<button class="icon js-icon" data-icon-text="random">icon graphic</button>
adding class attribute easy, need data-icon-text function attribute data displayed after .hover.
based on this previous question, tried modify image_tag:
<%= image_tag("randomv1.png", :class "icon js-icon" :data => { :icon-text => "random" }) %>
since delivering error, can create custom attribute?
try this:
you have revised class need =>
. then, have change :icon-text
string "icon-text"
.
<%= image_tag("randomv1.png", :class => "icon js-icon", :data => { "icon-text" => "random" }) %>
or
<%= image_tag("randomv1.png", :class => "icon js-icon", "data-icon-text" => "random") %>
i hope you
Comments
Post a Comment