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

              
                <!------ filter ------>
<div class="bg-light p-3 border-bottom mb-3">
  <div class="container-fluid">
    <div class="row">
      <div class="col-6">
        <select class="form-select js-filter" name="color">
          <option value="all">All Color</option>
          <option value="Red">Red</option>
          <option value="Blue">Blue</option>
          <option value="Green">Green</option>
        </select>
      </div>
      <div class="col-6">
        <select class="form-select js-filter" name="size">
          <option value="all">All Size</option>
          <option value="S">S</option>
          <option value="M">M</option>
          <option value="L">L</option>
        </select>
      </div>
    </div>
  </div>
</div>

<!------ result Message ------>
<p class="px-3"><span class="js-filter-msg"></span></p>

<!------ all items ------>
<div class="js-filter-items">
  <div class="js-filter-item bg-danger" data-color="Red" data-size="S">Red / S</div>
  <div class="js-filter-item bg-primary" data-color="Blue" data-size="M">Blue / M</div>
  <div class="js-filter-item bg-success" data-color="Green" data-size="M">Green / M</div>
  <div class="js-filter-item bg-danger" data-color="Red" data-size="L">Red / L</div>
  <div class="js-filter-item bg-primary" data-color="Blue" data-size="M">Blue / M</div>
  <div class="js-filter-item bg-success" data-color="Green" data-size="S">Green / S</div>
  <div class="js-filter-item bg-danger" data-color="Red" data-size="S">Red / S</div>
  <div class="js-filter-item bg-primary" data-color="Blue" data-size="L">Blue / L</div>
  <div class="js-filter-item bg-success" data-color="Green" data-size="S">Green / S</div>
  <div class="js-filter-item bg-danger" data-color="Red" data-size="L">Red / L</div>
  <div class="js-filter-item bg-primary" data-color="Blue" data-size="M">Blue / M</div>
  <div class="js-filter-item bg-success" data-color="Green" data-size="L">Green / L</div>
  <div class="js-filter-item bg-danger" data-color="Red" data-size="L">Red / L</div>
  <div class="js-filter-item bg-primary" data-color="Blue" data-size="S">Blue / S</div>
  <div class="js-filter-item bg-success" data-color="Green" data-size="L">Green / L</div>
  <div class="js-filter-item bg-danger" data-color="Red" data-size="M">Red / M</div>
  <div class="js-filter-item bg-danger" data-color="Red" data-size="M">Red / M</div>
  <div class="js-filter-item bg-success" data-color="Green" data-size="S">Green / S</div>
</div>
              
            
!

CSS

              
                /***** for hidden *****/
.d-none {
  display: none;
}

/***** for layout(optional) *****/
.js-filter-items {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(2, 1fr);
  margin: 1rem;
}

.js-filter-item {
  padding: 1rem;
  text-align: center;
  color: #fff;
}

              
            
!

JS

              
                function multi_filter(h, t, s, r = "") {
  let hidden = h;
  let targets = document.querySelectorAll(t);
  let selects = document.querySelectorAll(s);
  let result = document.querySelector(r);
  let result_msg = "";

  if (selects) {
    //****** for all select ******
    for (let i of selects) {
      i.addEventListener("change", () => {
        let hidden_num = 0;
        //*** for each target ***
        for (let ii of targets) {
          //*** delete hidden class ***
          ii.classList.remove(hidden);
          //*** check target every select ***
          for (let iii of selects) {
            //*** get select name value / option value / target data attribute ***
            let value = iii.value;
            let name = iii.getAttribute("name");
            let item_data = ii.getAttribute("data-" + name);
            //*** set hidden class ***
            // exist value & except all & item_data not match & no hidden class
            if (value && value !== "all" && value !== item_data && !ii.classList.contains(hidden)) {
              ii.classList.add(hidden);
              hidden_num++;
            }
          }
        }

        //****** result message ******
        if (result) {
          //*** not found ***
          if (hidden_num === targets.length) {
            result_msg = "No such thing..";
          }
          //*** found ***
          else {
            let result_num = targets.length - hidden_num;
            result_msg = result_num + " results";
          }
          result.innerText = result_msg;
        }
      });
    }
  }
}

//*** call ***
multi_filter("d-none", ".js-filter-item", ".js-filter", ".js-filter-msg");

              
            
!
999px

Console