I'm having trouble using the event.preventDefault(); for an ahref on my DOM

后端 未结 4 729
[愿得一人]
[愿得一人] 2021-02-09 13:09

I\'m having trouble using the event.preventDefault(); for an ahref on my DOM.

How do you prevent the url from posting a nofollow delete, as spe

4条回答
  •  死守一世寂寞
    2021-02-09 13:59

    It's an old question, but if you are using Rails 5.1+ with the vanilla UJS instead of jQuery one, neither event.preventDefault() nor returning false from the method stops rails-ujs from handling it. You need to explicitly call Rails.stopEverything(event)

    $('.trash_can a').click(function(event) {
      Rails.stopEverything(event);
      console.log('Clicked Delete');
    });
    

提交回复
热议问题