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

              
                <div id="app">
    <ul>
        <li><a href="https://cdpn.io/">https://cdpn.io</a></li>
        <li><a href="https://www.google.com/">https://www.google.com/</a></li>
        <li><a href="https://www.yahoo.co.jp/">https://www.yahoo.co.jp/</a></li>
        <li><a href="https://www.bing.com/">https://www.bing.com/</a></li>
        <li><a href="https://into-the-program.com/">https://into-the-program.com/</a></li>
    </ul>
</div>
              
            
!

CSS

              
                #app {
    width: 96%;
    max-width: 500px;
    margin: 40px auto;
    padding: 28px;
    border: 1px solid #ffffff;
    border-radius: 5px;
    background-color: transparent;
    box-shadow: 2px 2px 5px 0px rgba(200, 200, 200, 1);
    font-family: "Times New Roman";
}

ul li {
    margin: 0 0 20px 0;
}
              
            
!

JS

              
                //ページのドメインを取得
const domain = document.domain;
//取得したドメインを検証対象に指定
const regexp = new RegExp(domain);

//特定の要素内にあるa要素
const target = document.getElementById('app');
const elements = target.getElementsByTagName('a');

//ページ内すべてのa要素
//const elements = document.getElementsByTagName('a');

for(let element of elements){
    //a要素のhref(リンク)を取得
    let href = element.getAttribute('href');
    
    //a要素のhref(リンク)にドメインが含まれていなければ
    if(!regexp.test(href)){
        //a要素にtarget="_blank"を追加する
        element.setAttribute('target', '_blank');
        element.setAttribute('rel', 'noopener noreferrer');
    }
}
              
            
!
999px

Console