0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

クリックした文字の色を変える

Posted at

サンプルコード

index.php
<!DOCTYPE html>
<html lang="ja">
<head>
	<title>test</title>
	<link rel="stylesheet" type="text/css" href="test.css">
</head>
<body>
<ul>
	<li class="choice">A1</li>
	<li class="choice">A2</li>
	<li class="choice">A3</li>
	<li class="choice">A4</li>
</ul>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="test.js"></script>
</body>
</html>
test.css
body {
  font-size: 28px;
  font-family: font-family: "Avenir Next", Verdana, "ヒラギノ角ゴ Pro W3", "Hiragino Kaku Gothic Pro", "游ゴシック", "Yu Gothic", "メイリオ", Meiryo, Osaka, sans-serif;
}
.selected {
	color: red;
}
test.js
$(function() {
	$('.choice').on('click', function() {
		// $(this)は.choiceを指す変数
		var $selected = $(this);
		$selected.addClass('selected');
	})
})

結果

結果.PNG

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?