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

              
                <button type="button" onclick="walk(document.querySelector('body'))">Walk</button>
<hr>
<div id="images">
  <a href="#">
    <img alt="Alt" src="">
  </a>
  <a href="#">
    <img alt="Img Text" src="">
    Text
  </a>
</div>
<nav id="nav">
  <ul>
    <li><a href="#" title="About" id="test">About</a></li>
  </ul>
</nav>
<div id="copyright">
  Copyright © 2020 <a href="http://neo.s21.xrea.com/">Neo's World</a>, All rights reserved.
</div>
<div id="form">
  <textarea rows="1"></textarea>
  <input type="text">
  <select>
    <optgroup label="Food">
      <option value="tomato">Tomato</option>
      <option value="egg" label="Egg">Tameigou</option>
    </optgroup>
    <option>Etc</option>
  </select>
</div>
<hr>
<p>Author : <a href="http://neo.s21.xrea.com/">Neo</a></p>
              
            
!

CSS

              
                ul, p, input, select, textarea {
  margin: 0;
  vertical-align: top;
}
              
            
!

JS

              
                // https://github.com/kotachang/Word-Replacer-Chrome-Extension/blob/master/src/inject/inject.js
// https://gist.github.com/nkhil/befbaa8a9722e92db091f47a66fde7ca#file-brexit-js

function walk(node, debugDepth) {
  if(debugDepth == null) debugDepth = 0;
  const debugDepthIndent = '.'.repeat(debugDepth);
  switch(node.nodeType) {
		case  1:  // Element
		case  9:  // Document
		case 11:  // Document Fragment
      // 特殊系を先に処理する
      if(['TEXTAREA', 'INPUT'].includes(node.tagName) && !isEmpty(node.value)) {
        node.value = replaceValue(node.value);
        break;  // 子要素なし
      }
      else if(node.tagName === 'IMG' && !isEmpty(node.getAttribute('alt'))) {
        node.setAttribute('alt', replaceValue(node.getAttribute('alt')));
        break;  // 子要素なし
      }
      else if(['OPTGROUP', 'OPTION'].includes(node.tagName) && !isEmpty(node.getAttribute('label'))) {
        console.log('Opt', node.tagName);
        node.setAttribute('label', replaceValue(node.getAttribute('label')));
        // break しないことで optgroup 配下の option、および option 配下の TextNode も変換する
      }
      
			let child = node.firstChild; // childNodes を for ループする場合よりも要素の増減でバグりにくいと思う
      console.log(debugDepthIndent, node.nodeType, node.tagName, 'Start', child);
			while(child) {
        if(!['SCRIPT', 'STYLE', 'IFRAME', 'NOSCRIPT', 'FRAME'].includes(child.tagName)) {  // 必ず除外したいモノ
          //console.log(debugDepthIndent, 'Call Child', child.nodeType, child.tagName);
  				walk(child, debugDepth + 1);
        }
				child = child.nextSibling;
			}
      console.log(debugDepthIndent, node.nodeType, node.tagName, 'End');
			break;
		case 3:  // Text node
      if(node.nodeValue.trim() !== '') {
        console.log(debugDepthIndent, 'Text Node', `[${node.nodeValue}]`);
        node.nodeValue = replaceValue(node.nodeValue);
      }
			break;
    default:
      console.log(debugDepthIndent, node.nodeType, node.tagName, 'Unknown Node Type');
	}
}

// 仮で変換処理
function replaceValue(originalValue) {
  return originalValue.replace((/[a-z]/gu), match => match.toUpperCase());
}

function isEmpty(value) {
  return value === undefined || value === null || value === '';
}

document.addEventListener('DOMContentLoaded', () => {
  //walk(document.body);
  
  document.getElementById('test').addEventListener('click', () => {
    alert('Click!');
  });
});
              
            
!
999px

Console