3

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);
});
2

3 Answers 3

5

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

$('#ROW1 textarea, #ROW1 input').attr('someattr', 'value');
Sign up to request clarification or add additional context in comments.

1 Comment

Or if just the td have to be excluded: $('#ROW1 > td *') or similar.
1
$("#ROW1 td").each(function(){
   $.each($(this).children(
$(this).attr(//put some attribute)
));
})

3 Comments

I somehow still need to add children() after $(this) to access the elements, thanks
This does not make much sense... children does not accept an argument.
Your right, I didn't notice that. It's just that I need to put the 'TD' element to make my script work that I didn't notice that part of the answer
0

To get all child elements of #ROW1:

$('#ROW1').find('*')

4 Comments

But isn't the child elements of #ROW1 are the TD elements?
@MegaNairda: The find method doesn't get only the immediate children, but also children of children, so it will get the td elements and all elements inside it.
@Michael: No, what you refer to as "immediate children" are children and everything else are descendants... just like in real life. The children of my children are not my own children.
The problem with this code is that it includes also those table elements which I do not need to change the attributes. I only need to change the attributes of the elements within those elements.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.