我不知道为什么我坚持这个,但我就是!尝试克隆一个 div
,然后使用 jQuery 中的 children
修改其内容。我在这里遗漏了一些东西,因为它没有像我预期的那样工作。参见 fiddle :http://jsfiddle.net/v7A2T/
Javascript(jQuery):
$test = $('#clone-container').clone().appendTo('#append');
$test.children('h2').text('my clone'); // works
$test.children('.remove-row').remove(); // doesn't work
和 HTML:
<div id="clone-container" class="hidden">
<h2>Location name</h2>
<div class="table-responsive">
<table class="table">
<thead>
<th>one</th><th>two</th><th>three</th>
<th>four</th><th>five</th><th>six</th>
</thead>
<tbody>
<tr class="remove-row"><td colspan="6">Remove this text from clone</td></tr>
</tbody>
</table>
</div> <!-- .table-responsive -->
</div>
<div id="append"></div>
最佳答案
.remove-row
不是克隆元素的直接子元素。替换为:
$test.children('.remove-row').remove();
用这个:
$test.find('.remove-row').remove();
关于javascript - 在 jQuery 中查找克隆元素的子元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23661750/