Hi all! I want to add alert message via jquery when User clicks <div id="star">star</div>. But, It can''t work. Please teach me some advice. Thanks! # posts/index.html.erb [code] ... <% @posts.each do |post| %> <tr> <td><%= post.id %></td> <td><%= post.content %></td> <td></td> <div id="like"> <td>like</td> </div> <td><div id="star">star</div></td> <td><%= post.created_at.strftime("%Y年%m月%d日%H:%M:%S") %></td> <% end %> </tr> </table> .... [/code] # application.js [code] $(document).ready(function() { $("#star").click(function(){ alert("add_star"); }) }); [/code] -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi, Show us the error you are getting on that. Also, check your html code generated to see if the javascript libraries are loading correctly, in this case, the jquery library. If you are not on rails 3.1 you are probably loading the prototype files instead the jquery as needed. On Jul 28, 3:31 pm, 原田伸也 <haradashi...@gmail.com> wrote:> Hi all! I want to add alert message via jquery when User clicks <div > id="star">star</div>. > But, It can''t work. > Please teach me some advice. > > Thanks! > > # posts/index.html.erb > > [code] > ... > <% @posts.each do |post| %> > <tr> > <td><%= post.id %></td> > <td><%= post.content %></td> > <td></td> > <div id="like"> > <td>like</td> > </div> > <td><div id="star">star</div></td> > <td><%= post.created_at.strftime("%Y年%m月%d日%H:%M:%S") %></td> > <% end %> > </tr> > </table> > > .... > [/code] > > # application.js > [code] > $(document).ready(function() { > $("#star").click(function(){ > alert("add_star"); > }) > }); > [/code]-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Thu, Jul 28, 2011 at 2:31 PM, 原田伸也 <haradashinya-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi all! I want to add alert message via jquery when User clicks <div > id="star">star</div>. > But, It can''t work. > Please teach me some advice. > > Thanks! > > # posts/index.html.erb > > [code] > ... > <% @posts.each do |post| %> > <tr> > <td><%= post.id %></td> > <td><%= post.content %></td> > <td></td> > <div id="like"> > <td>like</td> > </div> > <td><div id="star">star</div></td> > <td><%= post.created_at.strftime("%Y年%m月%d日%H:%M:%S") %></td> > <% end %> > </tr> > </table> > > .... > [/code] > >You have multiple divs with ID = star. Change this to class and update the script and it should work.> # application.js > [code] > $(document).ready(function() { > $("#star").click(function(){ > alert("add_star"); > }) > }); > [/code] > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.com -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
It worked correctly.Thanks! -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.