it doesn't work jquery

Hi all! I want to add alert message via jquery when User clicks

star
.

But, It can’t work.

Please teach me some advice.

Thanks!

posts/index.html.erb


...

<% @posts.each do |post| %>

<tr>

<td><%= [post.id](http://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>

....

application.js


$(document).ready(function() {

$("#star").click(function(){

alert("add_star");

})

});

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.

Hi all! I want to add alert message via jquery when User clicks

star
.

But, It can’t work.

Please teach me some advice.

Thanks!

posts/index.html.erb

[code]

<% @posts.each do |post| %>

<%= [post.id](http://post.id) %>
<%= post.content %>
like
star
<%= post.created_at.strftime("%Y年%m月%d日%H:%M:%S") %>

<% end %>

[/code]

You have multiple divs with ID = star. Change this to class and update the script and it should work.

It worked correctly.Thanks!