2017.11.29
jQuery APIリファレンス .after()
説明
一致した要素のセットの各要素の後に、パラメータで指定された内容を挿入します。
シグネチャ
-
.after( content [, content ] )
追加version 1.0 引数:型 content:htmlString or Element or Text or Array or jQuery -
.after( function )
追加version 1.4 引数:型 function:Function( Integer index ) => htmlString or Element or Text or jQuery -
.after( function-html )
追加version 1.10 引数:型 function-html:
Function( Integer index, String html ) => htmlString or Element or Text or jQuery
サンプル1
すべての段落の後にいくつかのHTMLを挿入します。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>after demo</title>
<style>
p {
background: yellow;
}
</style>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<p>I would like to say: </p>
<script>
$( "p" ).after( "<b>Hello</b>" );
</script>
</body>
</html>
サンプル2
すべての段落の後にjQueryオブジェクト(DOM要素の配列に似ています)を挿入します。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>after demo</title>
<style>
p {
background: yellow;
}
</style>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<b>Hello</b>
<p>I would like to say: </p>
<script>
$( "p" ).after( $( "b" ) );
</script>
</body>
</html>
