在jQuery中查找克隆元素的子元素

tho*_*mad 2 javascript jquery children clone

我不知道为什么我会坚持这个,但我是!尝试克隆a div然后使用childrenjQuery 修改其内容.我在这里遗漏了一些东西,因为它没有像我期望的那样工作.请参阅小提琴: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
Run Code Online (Sandbox Code Playgroud)

和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>
Run Code Online (Sandbox Code Playgroud)

mus*_*ing 6

.remove-row不是克隆元素的直接子元素.替换这个:

$test.children('.remove-row').remove();
Run Code Online (Sandbox Code Playgroud)

有了这个:

$test.find('.remove-row').remove();
Run Code Online (Sandbox Code Playgroud)

小提琴