LoginSignup
0
1

More than 1 year has passed since last update.

Javascriptでクリックでclassを変更

Last updated at Posted at 2022-05-18

## 方法
参考記事

<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
 <style>
 .toggleClass {
  font-size: 30px;
  color: blue;
}
 </style>

<p id="text">
  クリックするとスタイルが変わります。
</p>
<button onclick="toggleFunc()">Button</button>


<script>
function toggleFunc() {
    let text = document.getElementById("text");
        text.classList.toggle("toggleClass");
}
</script>
</body>
</html>

上記で実装可能

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