Pen Settings

HTML

CSS

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

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

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.

HTML

              
                <div id="change_txt" contenteditable="true">編集可能な要素です。何か入力してください。</div>
<p id="result"></p>
<button id="stop_btn" onclick="this.disabled = true;">監視をストップする</button>
              
            
!

CSS

              
                #change_txt {
    background-color: #fff;
    margin: 20px 20px 0;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 8px;
}
#stop_btn {
    max-width: 200px;
    padding: 10px 14px;
    margin: 20px auto;
    display: block;
}
#result {
    margin: 10px 20px;
}
              
            
!

JS

              
                const result = document.querySelector('#result');
const stopBtn = document.querySelector('#stop_btn');

//オプション
const options = {
    // childList: true, //直接の子の変更を監視
    characterData: true,  //文字の変化を監視
    // characterDataOldValue: true, //属性の変化前を記録
    // attributes: true,  //属性の変化を監視
    subtree: true, //全ての子要素を監視
}
//コールバック関数
function callback(mutationsList, observer) {
    for(const mutation of mutationsList) {
        result.textContent = mutation.target.textContent;
    };
}
//ターゲット要素をDOMで取得
const target = document.querySelector('#change_txt');
//インスタンス化
const obs = new MutationObserver(callback);
//ターゲット要素の監視を開始
obs.observe(target, options);

stopBtn.addEventListener("click", function() {
    //ターゲット要素の監視を停止
    obs.disconnect();
    alert("ターゲットの監視を停止しました。")
});

              
            
!
999px

Console