Jquery does not work with <input> loaded with Ajax

Asked

Viewed 69 times

-1

The jQuery function works normally but when including the input ajax jQuery does not work for the input that was included!

I have the function:

$('.alerta').on('input', function() { 
    alert('Olá mundo!'); 
})

I have the input number 1 working with the above function:

<div>
    Número 1:<br>
    <input class="alerta" type="text" name="x"/><br><br>
</div>
<div class="div">
</div>

I have the ajax that includes the input number 2 in classe="div", but this does not work with the function of jQuery.

<?php
echo 'Número 2:<br>
<input class="alerta" type="text" name="y"/><br><br>';
?>
  • Thanks got much better is that I’m new here and I’m still learning to format the texts

1 answer

0

Tried to put it like this?

$('body').on('click', '#botao', function (e) {
   alert('teste');
}); 
  • Thanks Marcel! It worked $('body'). on('input', '.alert', Function(e) { Alert('Hello world! '); });

Browser other questions tagged

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