Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ add another resource


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


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.


Auto Save

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.


                	<ul class="list"></ul>



                .list {
  padding: 50px;
  background-color: #333;
  color: #fff;


var shops = [{
  keeper: '魯夫'
}, {
  keeper: '香吉士'
//綁定 .list,使用父元素控制子元素
var list = document.querySelector('.list');

//為了把資料回填到 li 中,故透過這個函式將資料抓出後渲染到網頁上
function updateList() {
  var str = ''; //組一個字串,內容為空
  var shopLen = shops.length; //資料長度 2
  for (var i = 0; shopLen > i; i++) {
    str += `<li data-num=${i}>${shops[i].keeper}</li>`
  } //字串加總
  list.innerHTML = str; //渲染到字串,並渲染到網頁
updateList(); //執行函式

// 確認點擊的店長是誰
function checkList(e) {
  var num =; //宣告一個 num ,當事件目標為自己,dataset 取出 num 的值
  console.log(; //確認 nodeName 是否為 'LI'
  if ( !== 'LI') { //若選到的 nodeName 不是 LI,就回傳(停止函式)
  console.log(`你選擇的店長為 ${shops[num].keeper}`); //顯示選擇內容

//在 list 新增 click 事件
list.addEventListener('click', checkList, false);