<!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 addClass(){ document.getElementsByTagName("p")[0].className = "red"; } </script> <style> .red{ color:#FF0000; } </style> </head> <body> <p>テキストテキストテキストテキストテキスト</p> <input type="button" value="click" onclick="addClass();"> </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.onload = function(){ document.getElementsByTagName("input")[0].onclick = function(){ document.getElementsByTagName("p")[0].className = "red"; } } </script> <style> .red{ color:#FF0000; } </style> </head> <body> <p>テキストテキストテキストテキストテキスト</p> <input type="button" value="click"> </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(){ document.getElementsByTagName("input")[0].addEventListener("click",function(){ document.getElementsByTagName("p")[0].className = "red"; }); }); </script> <style> .red{ color:#FF0000; } </style> </head> <body> <p>テキストテキストテキストテキストテキスト</p> <input type="button" value="click"> </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(){ $("input").click(function(){ $("p").addClass("red"); }); }); </script> <style> .red{ color:#FF0000; } </style> </head> <body> <p>テキストテキストテキストテキストテキスト</p> <input type="button" value="click"> </body> </html>