0
0

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.

javascript学習① 20190410

Posted at

#javascriptについて学習をする

javascript.html
要素を全て読み込んで動作を加えたいため、
bodyタグの後半にscriptタグを書くことが一般的

<body>
    <div id="target" class="box"></div>

<script>
    'use strict';  

    document.getElementById('target').addEventListener('click', function(){
        document.getElementById('target').style.background = 'pink';
    });

    const target = document.getElementById('target')
</script>

document.getElementById('target')は要素をidで指定してgetする命令
.addEventListener('click', function(){〇〇}:何かをしたら何かの処理を行う(例)clickをした時にfunctionに記した動作を行う

fuctionには何個でも処理を追加することができる
document.getElementById('target').style.background = 'pink';getした要素に対して.で繋いで処理をかく

const hoge = 命令 で変数に置き換えることができる
<script>
for (let i=0;i<10;i++){
    if(i===num){
    }else{
    }
}
</script>
0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?