0

I've asked a question recently on how to change 2 icons to text on click. The solution worked for a while, but now it's not working. Is there another way to do it or is the problem in the code? I face the problem with other scripts very often.

application.js

//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require jquery.ui.all
//= require jquery.turbolinks
//= require jquery_nested_form
//= require_tree .

show.html.erb

<div class="thumbsup">
<%= link_to image_tag('othericons/thumbsup_off.PNG', height: '20', width: '20', like_post_comment_path(comment.post_id, comment), method: :put, :remote => true %>
</div>

<div class="thumbsdown">
<%= link_to image_tag('othericons/thumbsdown_off.PNG', height: '20', width: '20', dislike_post_comment_path(comment.post_id, comment), method: :put, :remote => true %>
</div>

html output

<div class="thumbsup">
    <a data-method="put" data-remote="true" href="/posts/1/comments/4/like" rel="nofollow">
        <img alt="Thumbsup off" height="21" src="/assets/othericons/thumbsup_off.PNG" width="20" />
    </a>
</div>

<div class="thumbsdown">
    <a data-method="put" data-remote="true" href="/posts/1/comments/4/dislike" rel="nofollow">
        <img alt="Thumbsdown off" height="21" src="/assets/othericons/thumbsdown_off.PNG" width="20" />
    </a>
</div>

icons.js

$('.thumbsdown a, .thumbsup a').on('click', function() 
{
    $('.thumbsdown').before('You voted')
    $('.thumbsdown, .thumbsup').remove()
})
Community
  • 1
  • 1
Absurdim
  • 233
  • 3
  • 15

1 Answers1

0

If it was working before, the problem is likely an issue with Turbolinks:

$(document).on("click", ".thumbsdown a, .thumbsup a", function() {
    $('.thumbsdown').before('You voted')
    $('.thumbsdown, .thumbsup').remove()
});
Richard Peck
  • 76,116
  • 9
  • 93
  • 147
  • Doesn't work properly. It changes images to text on click, but it changes it for all comments on the page at the same time. – Absurdim May 05 '14 at 08:34