戻る

全要素を別の要素で包む

jQuery

<!DOCTYPE html>
<html lang="ja-JP">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,user-scalable=yes,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.5">
<title></title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
$(function(){
	$("input").click(function(){
		$("#first strong").wrapAll("<h1></h1>");
		
		//strong要素以外はh1要素の外に追いやられる
		$("#second strong").wrapAll("<h1></h1>");
	});
});
</script>
</head>
<body>
<input type="button" value="click">
<div id="first">
	<strong>テキストテキスト</strong>
	<strong>テキストテキスト</strong>
</div>
<div id="second">
	<strong>テキストテキスト</strong>
	テキストテキスト
	<strong>テキストテキスト</strong>
</div>
</body>
</html>

inserted by FC2 system