jquery的文檔操作

來源:互聯網
上載者:User

標籤:

appendTo(content)概述

把所有匹配的元素追加到另一個指定的元素元素集合中。

實際上,使用這個方法是顛倒了常規的$(A).append(B)的操作,即不是把B追加到A中,而是把A追加到B中。

<<<<<<<<<<<<<<<<<<<<<<<------------->>>>>>>>>>>>>>>>>>>>>

在jQuery 1.3.2中,appendTo, prependTo, insertBefore, insertAfter, 和 replaceAll這個幾個方法成為一個破壞性操作,傳回值是所有被追加的內容,而不僅僅是先前所選中的元素。所以,要選擇先前選中的元素,需要使用end()方法,參見例二。

<<<<<<<<<<<<<<<<<<<<<<<------------->>>>>>>>>>>>>>>>>>>>>

參數contentString

用於被追加的內容

樣本描述:

把所有段落追加到ID值為foo的元素中。

HTML 程式碼:
<p>I would like to say: </p><div></div><div></div>
jQuery 代碼:
$("p").appendTo("div");
結果:
<div><p>I would like to say: </p></div><div><p>I would like to say: </p></div>
描述:

建立段落追加div中並加上一個class

HTML 程式碼:
<div></div><div></div>
jQuery 代碼(例2):
 $("<p/>")   .appendTo("div")   .addClass("test")   .end()   .addClass("test2");
結果:
<div><p class="test test2"></p></div><div><p class="test"></p></div>

其它相關操作:
append,prepend,prependTo,after,before,insertAfter,insertBefore,wrap系列,remove,detach,clone,replaceWith,replaceAll.

jquery的文檔操作

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.