jQuery wrap()メソッド
例
各<p>要素の周りに<div>要素をラップします。
$("button").click(function(){
$("p").wrap("<div></div>");
});
定義と使用法
wrap()メソッドは、選択された各要素の周りに指定されたHTML要素をラップします。
構文
$(selector).wrap(wrappingElement,function(index))
Parameter | Description |
---|---|
wrappingElement | Required. Specifies what HTML element(s) to wrap around each selected element Possible values:
|
function(index) | Optional. Specifies a function that returns the wrapping element
|
自分で試してみてください-例
するdocument.createElement()を使用して要素を作成し、選択した各要素をラップする方法。
を使用して、選択した各要素をラップする対象を指定します。
を切り替える方法。