20140226【JS】jQueryで複数のセレクタの指定

お題

jQueryで複数のセレクタの指定

プログラム概要

jQueryで複数のセレクタに一致する要素を一度に選択し

コンソールに出力する

ソース


<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>hoge</title>
<script src="jquery-1.11.0.js"></script>
<body>
<h1>複数のセレクタの指定</h1>

<div class="description">div要素のコンテンツ</div>
<div>
    <span class="notation">span要素のコンテンツ</span>
</div>
<script>
$(function(){
	// class属性がdescriptionのdiv要素とnotationのspan要素
	$('div.description, span.notation').each(function(i, e){
		console.log($(e).text());
	});
});
</script>
</body>
</html>

実行結果

   div要素のコンテンツ

   span要素のコンテンツ