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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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 class="topics_box">
  <!-- もしリンクあり見出しがあるなら<div class="topics_link">アンカーリンク</div>が出る -->
  <div class="topics_single_list">
    <!-- ここにアンカーリンクが生成される -->
  </div>
</div>
<h2 class="topics_content">
  <h2 class="ttl_link">見出し1</h2>
  <div class="topics_txt">
    本文
  </div>
  <h2 class="ttl_link">見出し2</h2>
  <div class="topics_txt">
    本文
  </div>
    <h2 class="ttl_link">見出し3</h2>
  <div class="topics_txt">
    本文
  </div>
</div>

              
            
!

CSS

              
                .topics_link{
  font-size:20px;
}
.topics_content{
  margin-top:20px;
}
.ttl_link{
  font-size:20px;
  margin-bottom:10px;
}
.topics_txt{
  height:200px;
}
              
            
!

JS

              
                $(function(){

var wrapper_single = $('.wrapper_single');

//空の配列を作る
var ttl_name = [];
var ttl_link = [];

//見出しがあるなら下記追加
if($('.ttl_link').length){
  $('.topics_box').prepend('<div class="topics_link">アンカーリンク</div>');
}else{
}

//eachでttl_linkをそれぞれ見る
$('.ttl_link').each(function(i){
  //見出しにidを連番を振る
   $(this).attr('id','link_' + (i+1));
   //ttl_nameにタイトルを格納
   var name =$(this).text();
   ttl_name.push(name);

   //ttl_linkにidを格納
   var link =$(this).attr('id');
   ttl_link.push(link);

   var single_list =$('.topics_single_list');
   single_list.append('<div><a href="#'+ttl_link[i]+'">'+ttl_name[i]+'</a></div>');
});
});

              
            
!
999px

Console