我有以下DIV結構:循環類中的每個Jquery的
<div id='mainDiv'>
<div id='childDiv1' class='childElement'>Content1<div>
<div id='childDiv2' class='childElement'>Content2<div>
</div>
在我的jQuery的操作之一,我刪除的 所有內容mainDiv
strHtmlNewChildHtml = '<div id='childDiv1' class='childElement'>New Content1<div><div id='childDiv2' class='childElement'>New Content2</div>';
$("#mainDiv").html('');
$("#mainDiv").html(strHtmlNewChildHtml);
並使用循環類名添加New Html。
$('.childElement').each(function() {
//It is looping 4 times while new HTML having only 2 divs
});
我的問題:正如我已刪除了老2個的子元素,並同時循環運行4次添加2個新的子元素之後?
'$( '是childElement')'不會迴路單一的時間,其實 –
什麼是'childElement' – brk
有可能很多與問題更錯了也 - 樣,有什麼是'strHtmlNewChildHtml' –