Catch <a> tag click event when it hasn’t loaded yet in $(Document). ready MVC - RAZOR

Asked

Viewed 52 times

0

I create dynamically in my View via Razor data that is populated in a table.

On my last td I have the following elements:

<td class="row-actions fixed-col"><a name="excFaturamento"><i class="fa fa-times"/></a></td>

This element has not yet been created at the time of

$(document).ready

In my file . js put as follows:

$('[name="excFaturamento"]').on('click', 'a', function () {

Remembering that my table is mounted via Razor with data that is inside a viewbag, that is the page will never be loaded before the ready Document.

However the same does not catch my click event. Can anyone help me?

  • Welcome to stackoverflow. It’s interesting to read the tour to understand how the site works. http://answall.com/tour

  • 1

    If it hasn’t been charged yet, then it doesn’t exist.

1 answer

1

This code does what you asked. But..... it will only "execute" the command of click after loading the page. That is, it will only run it after it has been loaded.

$(document).ready(function() {

  $('#excFaturamento').click(function() {
    alert("clicou");
  });
});
<!DOCTYPE html>
<html>

<head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
</head>

<body>
  <table>
    <tr>
      <td class="row-actions fixed-col">
        <a id="excFaturamento" name="excFaturamento">Link<i class="fa fa-times" /></a> 
      </td>
    </tr>
  </table>
</body>

  • It depends on what you’re trying to do. I took my test slowing down and clicked the button. " After" it is loaded, it recognizes the click. Before that, "soon [or before the page is loaded, the button] does not exist." - @Edilson

  • this way that you sent also does not work, the problem that I am using Razor in my view to assemble this table, so I have to figure out some way to take this event dynamically, because it will never be mounted before the ready Ocument

  • Make this clear in your topic so that others also do not get confused, and so answer you satisfactorily.

Browser other questions tagged

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