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

              
                %table
  %thead
    %tr
      %th.doTheSort(data-type="string")
        名前
        %span
      %th.doTheSort(data-type="integer")
        点数
        %span
  %tbody
    %tr
      %td Tanaka
      %td 38
    %tr
      %td Ikeda
      %td 4
    %tr
      %td Koike
      %td 22
    %tr
      %td Nonaka
      %td 89

              
            
!

CSS

              
                body { padding: 1rem; }

table, tr, th, td {
  border: 1px solid #eee;
  text-align: left;
  width: 50%;
}

              
            
!

JS

              
                $(function() {
  // 並べ替え順を設定する
  var sortOrder = 1; // 1:昇順, 2:降順
  
  // 列をクリックしたら
  $('.doTheSort').on('click', function() {
    // data-type を取得する
    var type = $(this).data('type'); // string, integer
    // 何カラム目かを取得する
    var colNum = $(this).index(); // 0, 1, ...
    // 行全体を取得する
    var $rows = $('tbody>tr');
    // 行を点数で並び替える
    $rows.sort(function(a, b) {
      return compare(a, b, type, colNum) * sortOrder;
    });
    // tbody を並び替えられた行全体に入れ替える
    $('tbody').empty().append($rows);
    // ソートを表す矢印を表示する
    var arrow = sortOrder === 1 ? '▲' : '▼';
    $('.doTheSort > span').text('');
    $(this).find('span').text(arrow);
    // 並び順を反転する
    sortOrder *= -1;
  });

  function compare(a, b, type, colNum) {
    var _a = $(a).find('td').eq(colNum).text();
    var _b = $(b).find('td').eq(colNum).text();

    if (type == 'string') {
      if (_a < _b) { return -1; }
      if (_a > _b) { return 1; }
      return 0;
    } else {
      _a *= 1;
      _b *= 1;
      return _a - _b;
    }
  }
});

              
            
!
999px

Console