Doubt with Jquery

Asked

Viewed 17 times

0

inserir a descrição da imagem aqui

I have the image attached when I click on the checkbox, I can give Highlight on that line via the following code :

    $("input[type='checkbox']").change(function (e) {
    if ($(this).is(":checked")) {
        $(this).closest('tr').addClass("highlight_row");
    } else {
        $(this).closest('tr').removeClass("highlight_row");

    }
});

Pórem is tending to make that when I click two input fields that I have in the end win the REQUIRED property. It must be something simple, but I’m skating on it. That’s a line from where I can get 'n' lines.

  • Edit your question and include table html with inputs

  • you can give a find on the element since it has the $(this), would look something like this: $(this).parent().find().('.classe_do_input').attr('required', true); with the parent you will rise to the level of the line and after that search the element with the class you need.

  • @arllondias I think using the attr will not give, use the .prop("disabled", true) may result in alternative

1 answer

0

Taking into account that the $(this).closest('tr') is the <tr />. just use the .find() to find the inputs of the type text. Example:

to add the required:

  • $(this).closest('tr').find('input[type=text]').attr('required', 'required');

or to remove the required:

  • $(this).closest('tr').find('input[type=text]').removeAttr('required');

Browser other questions tagged

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