开发者

Click event by jquery in Rails

开发者 https://www.devze.com 2023-03-11 06:03 出处:网络
I have partial on main page: <div id=\'calendar_links\'> <%= link_to day_of_week, root_path(:day => day), :class => \'active_calendar_link\' %>

I have partial on main page:

    <div id='calendar_links'>
      <%= link_to day_of_week, root_path(:day => day), :class => 'active_calendar_link' %>
    </div>

I want to make开发者_运维技巧 that - after click to this link, this link redirect to main page with day parameter and I want to after clicking this day be without :class => 'active_calendar_link'.

I write this jquery code in application.js file, but it didn't work, why? :

$(document).onDomReady(function(){
 $('#calendar_links').click(function()
  $(this).removeClass('active_calendar_link')
 }); }); })

How to correct to?


In your code, you're checking the click event on the div, not on the anchor tag.

Then, this refers to the wrong object.

Moreover, it seems that you really redirect to another page since I can't see any preventDefault() action. So obviously, it can't work.


$(function(){
  $(".active_calendar_link").click(function(){
    $(this).removeClass("active_calendar_link");
    return true;
  })
})
0

精彩评论

暂无评论...
验证码 换一张
取 消