Failed to load a function with jQuery selector

Asked

Viewed 24 times

0

When you click a button, I need you to press my JS function. To load this function, clicking the button only works if you inform the button with the attribute onclick, stating the name of the function. When I try to access through the button class selector, the function does not press.

<button type="button" class="btn btn-danger btn-xs excl-receita"><i class="fa fa-trash"></i></button>

The JS function I intend to use:

$('.excl-receita').off('click').on('click', function () { });
  • Pq is using .off? Would just $('.excl-receita').on('click', function () { });

  • With . off or without, does not work.

  • Even with .off should work. I just questioned your use rs. It might not be working for several reasons: is the element dynamic? The code is before or after the element?

  • JS is loaded before the page. And the element is dynamic.

1 answer

0


Try with

$('body').on('click', '.excl-receita', function () { });

Browser other questions tagged

You are not signed in. Login or sign up in order to post.