Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="enemy monster slime">スライムA</div>
<div class="enemy monster slime">スライムB</div>
<div class="enemy monster goblin">ゴブリン</div>
<div class="enemy monster ogre">オーガ</div>

<div class="nakama human yuusya">勇者</div>
<div class="nakama human magicuser">魔法使い</div>
<div class="nakama human sensi">戦士</div>
<div class="nakama monster goblin">ゴブリン</div>

<div class="npc human townpeople">町人</div>
<div class="npc human soldier">兵士</div>
<div class="npc human king">王様</div>
<div class="npc human inn">宿屋</div>

<div id="fff" class="magic fire">ファイヤ</div>
<div id="hhh" class="magic ice">ヒャダイン</div>
<div id="ttt" class="magic thunder">サンダー</div>
<div id="rrr" class="magic recov">ホイミ</div>


<p id="result1"></p>
              
            
!

CSS

              
                
              
            
!

JS

              
                console.log("start");
var enemys = document.getElementsByClassName('enemy');

console.log("▼クラス名enemysで取ってきたHTMLCollection要素に対し、先頭の要素からenemyクラスを削除すると要素ごと消えるので真後ろの要素がいまのiになってしまう、その後i++すると1個飛ばしみたいになっちゃう");
for(var i=0; i<enemys.length; i++) {
    console.log(enemys[i]);
}
for(var i=0; i<enemys.length; i++) {
  console.log('I am ' + enemys[i].textContent);
  enemys[i].classList.remove('enemy');
  console.log('who am I? I am ' + enemys[i].textContent);
}

console.log("▼クラス名nakamaで取ってきたHTMLCollection要素に対し、後ろの要素から順にnakamaクラスを削除すると順番はズレなくて要素ごと消える");
var nakamas = document.getElementsByClassName('nakama');
for(var i=0; i<nakamas.length; i++) {
    console.log(nakamas[i]);
}
for(var i=nakamas.length-1; i>=0; i--) {
  console.log('I am ' + nakamas[i].textContent);
  nakamas[i].classList.remove('nakama');
  //console.log('who am I? I am ' + nakamas[i].textContent); //このnakama[i]には既にアクセスできない
}
console.log('nakamas.length : ' + nakamas.length);


console.log("▼クラス名npcで取ってきた要素に対し、humanクラスを削除しても要素は残る");
var npcs = document.getElementsByClassName('npc');
for(var i=0; i<npcs.length; i++) {
    console.log(npcs[i]);
}
for(var i=0; i<npcs.length; i++) {
  console.log('I am ' + npcs[i].textContent);
  npcs[i].classList.remove('human');
  console.log('who am I? I am ' + npcs[i].textContent);
}
console.log('npcs.length : ' + npcs.length);

var magics = document.getElementsByClassName('magic');
var magicArray = Array.prototype.slice.call(magics); //HTMLCollectionから配列にしてあげる
for (var i=0; i<magicArray.length; i++) {
  let id = magicArray[i].id;
  let magicElm = document.getElementById(id);
  console.log('I am ' + magicElm.textContent);
  magicElm.classList.remove('magic');
  console.log('who am I? I am ' + magicElm.textContent);
}
console.log('magics.length : ' + magics.length);
console.log(magicArray);
              
            
!
999px

Console