Catch click event a tag when it has not yet loaded in $ (document) .ready MVC - RAZOR [closed]

0

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

In 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 was not created at the time of

$(document).ready

In my .js file I put it like this:

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

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

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

    
asked by anonymous 10.12.2015 / 18:34

1 answer

1

This code does what you asked for. But ..... it will only "execute" the click command after page loading. That is, it will only run 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><tdclass="row-actions fixed-col">
        <a id="excFaturamento" name="excFaturamento">Link<i class="fa fa-times" /></a> 
      </td>
    </tr>
  </table>
</body>
    
10.12.2015 / 18:48