2012-07-19 124 views
1

我需要用另一個替換一個div,也需要另一個容器被刪除。請參閱我的代碼:jQuery用另一個替換一個Div

<a id="load-more" href="#"> 
<div class="text">Load more</div> 
<div id="infscr-loading"> 
<img alt="Loading..." src="../loading_small.gif" style="display: none; "> 
<div">No more posts to load</div> 
</div> 
</a> 

我需要這樣的:

<span class="text">Load more</span> 

這種替換:

<div">No more posts to load</div> 

所以,我的結果應該是:

<a id="load-more" href="#"> 
<div">No more posts to load</div> 
<div id="infscr-loading"> 
<img alt="Loading..." src="../loading_small.gif" style="display: none; "> 
</div> 
</a> 

這是可能做什麼?

+0

是的,這是可能的。你有什麼嘗試? – iambriansreed 2012-07-19 19:55:42

回答

1

您的標記已在<div">標籤錯誤,可能是你不小心刪除的類名或ID。我會假設更換div有id屬性。

要改變<div class="text">位的,你需要做的內容:

$('div.text').replaceWith($('#replacement')); 

這既消除了text股利和移動#replacement div來的text div的位置。

1
$('div.text').replaceWith($('#replacement').html());