In jQuery, how can I make a selection of an element using "this", inside one I’m already selecting

Asked

Viewed 19 times

2

I tried to do so:

$(document).ready(function(){

  $("#formulario").submit(function(){

    //Esse trecho não funciona
    $(this "input").each(function(){});

  });

});

1 answer

2

You can use $("input", this) or $(this).find("input").

Example:

$('div').each(function() {
  $("input", this).val('teste'); // seta o value
  $(this).find("input").attr('disabled', false); // tira o disabled
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
  <input type="text" disabled/>
</div>

Browser other questions tagged

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