戻る

nth-last-of-type疑似クラス

CSS3

<!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>
<style>
div p:nth-last-of-type(2){
	color:#FF0000;
}
</style>
</head>
<body>
	<div>
	<p>テキストテキストテキストテキスト</p>
	<p>テキストテキストテキストテキスト</p>
	<p>テキストテキストテキストテキスト</p>
	<p>テキストテキストテキストテキスト</p>
	<address>テキストテキストテキストテキスト</address>
	</div>
</body>
</html>

HTML5

<!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>
window.addEventListener("load",function(){
	for(var i = 0; i < document.querySelectorAll("div p:nth-last-of-type(2)").length; i++){
		document.querySelectorAll("div p:nth-last-of-type(2)")[i].style.color = "#FF0000";
	}
});
</script>
</head>
<body>
	<div>
	<p>テキストテキストテキストテキスト</p>
	<p>テキストテキストテキストテキスト</p>
	<p>テキストテキストテキストテキスト</p>
	<p>テキストテキストテキストテキスト</p>
	<address>テキストテキストテキストテキスト</address>
	</div>
</body>
</html>

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(){
	$("div p:nth-last-of-type(2)").css("color","#FF0000");
});
</script>
</head>
<body>
	<div>
	<p>テキストテキストテキストテキスト</p>
	<p>テキストテキストテキストテキスト</p>
	<p>テキストテキストテキストテキスト</p>
	<p>テキストテキストテキストテキスト</p>
	<address>テキストテキストテキストテキスト</address>
	</div>
</body>
</html>

inserted by FC2 system