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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

              
                <!DOCTYPE html>
<html lang="jp">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>addNameBtn</title>
</head>
<body>
    <ol id = "lists">  <!– ol の要素で1.2.3...と自動で入力される->
        <li>ハマーン</li>
        <li>マウアー</li>
        <li>ナナイ</li>
    </ol>
 
    <button id = "addBtn">名前を増やす</button>
    
    <script src = "index.js"></script>
</body>
</html>
              
            
!

CSS

              
                
              
            
!

JS

              
                //リファクタリング
const button = document.getElementById("addBtn");
const namelists = document.getElementById("lists");
 
//メソッド
function addList(user){    //for分で繰り返し
    const list = document.createElement("li");      //HTML要素を作成できるメソッド(今回はli要素を作成。divとかも作れる)
    list.innerText =user.name+"\n"+user.email+"\n"+user.address.zipcode;       //userの名前とメルアド ”\n"はただ改行入れただけ
    namelists.appendChild(list);    //listのテキストをhtmlのliに追加する処理
    console.log(user.email);
}
 
//メソッド
async function getUsers(){
 //この辺はデータのやり取り
    const res = await fetch("https://jsonplaceholder.typicode.com/users");
    const users = await res.json();  /*実際のユーザーのJSONデータを users にいれる*/
    return users;
    console.log(users);
}
 
async function listUsers(){
    const users = await getUsers();
    users.forEach(addList);       //リストに追加する処理 DOM操作
}
 
//イベント
window.addEventListener("load",listUsers);
 
button.addEventListener("click",listUsers);
 
              
            
!
999px

Console