How to access the elements inside a dynamic element with jquery

Asked

Viewed 194 times

1

Good afternoon.

I have a question. I used the load (jquery) command to load a page, and within it there is a form. When this form is processed, it should change the div that is in the same load hierarchy.

I’m trying to do like this:

$("#conteudo").on('form[name=formCadastraQuadra]').submit(function(){

   //como eu acesso os elements inputs deste cara?

});

Thank you very much

  • Forehead with $("#conteudo").on('submit', 'form[name=formCadastraQuadra]', function(){

  • Thank you very much. But how do I access the Elements with (each) $(this).each('input', function(i, obj){
 alert(obj);
 });

  • What elements? form? elements can be clearer?

  • If I know what you mean $(this).find('input').each(...

1 answer

1

When using a delegated event the this inside the callback is the element to which the event was delegated. Thus the this will be the form and to fetch the inputs descended from that form you can use the .find(). Something like that:

$("#conteudo").on('submit', 'form[name=formCadastraQuadra]', function(){
    $(this).find('input').each(function(i, el){
        // aqui o "el" e o `this` corresponde ao elemento iterado

Browser other questions tagged

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