在頁面加載時,我想用div
包裝標題範圍並將其移動到相關的body div的前面。 即,將hApplicant1 span
移動到tabApplicant1 div
等的前面jQuery - 移動相關元素
如何編寫jQuery來完成此操作?謝謝 !
考慮:
<div>
<div id="header">
<span id="hDummy"></span>
<span id="hApplicant1">James Smith</span>
<span id="hApplicant2">John Doe</span>
<span id="hApplicant3"></span>
<span id="hApplicant4"></span>
</div>
<div id="body">
<div id="tabApplicant1">...</div>
<div id="tabApplicant2">...</div>
</div>
</div>
<div>
<div id="header2">
<span id="h2Dummy"></span>
<span id="h2Applicant1">Black Smith</span>
<span id="h2Applicant2">Shoe Maker</span>
<span id="h2Applicant3"></span>
<span id="h2Applicant4"></span>
</div>
<div id="body2">
<div id="tab2Applicant1">...</div>
<div id="tab2Applicant2">...</div>
</div>
</div>
的結果應該是這樣的:
<div>
<div id="header">
<span id="hDummy"></span>
<span id="hApplicant3"></span>
<span id="hApplicant4"></span>
</div>
<div id="body">
<div><span id="hApplicant1">James Smith</span></div>
<div id="tabApplicant1">...</div>
<div><span id="hApplicant2">John Doe</span><div>
<div id="tabApplicant2">...</div>
</div>
</div>
<div>
<div id="header2">
<span id="h2Dummy"></span>
<span id="h2Applicant3"></span>
<span id="h2Applicant4"></span>
</div>
<div id="body2">
<div><span id="h2Applicant1">Black Smith</span></div>
<div id="tab2Applicant1">...</div>
<div><span id="h2Applicant2">Shoe Maker</span><div>
<div id="tab2Applicant2">...</div>
</div>
</div>
顧我們有同樣的想法。只是想知道,你的最後是什麼.parent()? –
@Joseph:我修改了我的問題,它現在有兩個重複的容器div。你能幫助解決這個難題嗎?謝謝! – nandin
@Richard D - 檢查您生成的代碼。 'span [id^= hApplicant]'不包含在'div's中。這是因爲他們被留在'#頭文件中。 –