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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -