Pen Settings



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


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


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.


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.


                <div class='aaa' data-itemid="id001">test<span class="sum"></span></div>
<div class='aaa' data-itemid="id002">test<span class="sum"></span></div>
<div class='aaa' data-itemid="id003">test<span class="sum"></span></div>

<div class='bbb' data-itemid="id001"><span>1</span></div>
<div class='bbb' data-itemid="id002"><span>2</span><span>1</span></div>
<div class='bbb' data-itemid="id003"><span>0</span><span>0</span></div>





  function isItemNumSum(){
    var arr = [];
    var arrNum = [];
    $('.bbb').each(function() {
      var itemId = $(this).data('itemid');

      var arrNum = $(this).find('span').map(function(){//配列に入れる
        return Number( $(this).text() );//Numberでテキストを数に変換

      //var sum = arr.reduce((a,x) => a+=x);//配列から合計数を出す(エラーになってしまった)
      var sumFn  = function(arr) {
        var sum = 0;
        arr.forEach(function(elm) {
            sum += elm;
        return sum;

      arr.push( {id : itemId, num : sumFn(arrNum)} );//配列に追加


    for(i in arr){//bbbで作った配列をまわす
        if($(this).data('itemid') == arr[i].id){//同じIDの時にbbbのspanの合計値を入れる
          if(arr[i].num != '0'){
          } else {

    if( $('.sum').text() == '0' ){