Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery changing attribute of the element within an element

I have a problem here, I couldn't set the attribute I wanted inside my table.

<tr id="ROW1" class="duplicate">
  <td>
    <textarea class="cl_text" cols="20" name="descriptions1"></textarea>
  </td>
  <td>
    <input class="cl_form" size="10" value="" name="expectedDate1">
  </td>
  <td>
    <input class="cl_form" size="10" value="" name="slxInput1">
  </td>
  ...
  ...
</tr>

I can change the attribute of the TD element but not those within it. I need to change all those elements within the TD elements, it's easy to change the first and last elements but how about the others? If possible, I just wanted to a loop that will do change all those attributes under #ROW1

EDITED: I added my code that isn't working;

$( "#ROW" + Num ).each(function(index) {
    temp = $(this).children(":first").attr("name");
    $(this).children(":first").attr("name", temp+Num);
});
like image 615
MegaNairda Avatar asked Dec 12 '25 15:12

MegaNairda


1 Answers

To change an attribute for all inputs and textareas in the table row:

$('#ROW1 textarea, #ROW1 input').attr('someattr', 'value');
like image 189
Guffa Avatar answered Dec 15 '25 07:12

Guffa