Skip to content Skip to sidebar Skip to footer

Can't Select Link_to Tag As Jquery Selector Rails

I am a beginner rails dev. I got this link_to tag with the class of 'comments_link' %h2= link_to pluralize(@recipe.comments.count, 'Comment'), '#', class: 'comments_link , btn btn-

Solution 1:

You have a comma in the class name which I assume would invalidate the class name. Check developer tools in order to inspect the element to see if .comment_link actually exists. If not, remove the comma and try again

Solution 2:

Assuming this is a problem with turbolinks, you can fix this by preventing the default action on the click in your event handler (which is a good idea anyway):

$(document).ready(function(){
  $(".comments_link").click(function(e){
    e.preventDefault();
    $(".section").toggle();
  });                               
})

Post a Comment for "Can't Select Link_to Tag As Jquery Selector Rails"