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

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

android - How to create dynamically Fragment pager adapter -

1111. appearing after print sequence - php -