javascript - jQuery changing attribute of the element within an element - Stack Overflow

I have a problem here, I couldn't set the attribute I wanted inside my table.<tr id="ROW1&

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

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);
});
Share Improve this question edited May 15, 2012 at 11:16 MegaNairda asked May 7, 2012 at 11:30 MegaNairdaMegaNairda 8392 gold badges14 silver badges25 bronze badges 2
  • Please post your code (edit the question and add it). – Felix Kling Commented May 7, 2012 at 11:37
  • You should browse through the jQuery documentation: api.jquery./category/selectors and api.jquery./category/traversing – Felix Kling Commented May 7, 2012 at 11:39
Add a ment  | 

3 Answers 3

Reset to default 5

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

$('#ROW1 textarea, #ROW1 input').attr('someattr', 'value');
$("#ROW1 td").each(function(){
   $.each($(this).children(
$(this).attr(//put some attribute)
));
})

To get all child elements of #ROW1:

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742301672a4418145.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信