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