↓この部分でeach(function())に引数をいれてeach以降にでてくる$(this)を削除する方法を教えてほしいです。
} else { $(".list").find("li").each(function() { if($(this).data('category-type') === cateVal) { $(this).show(); } else { $(this).hide(); } }); }
・HTML全体 <!doctype html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> <meta name="format-detection" content="telephone=no"> <title>jQuery</title> <link rel="stylesheet" href="../../common/css/reset.css"> <link rel="stylesheet" href="../../common/css/base.css"> <link rel="stylesheet" href="./css/style.css"> </head> <body> <div class="wrapper"> <div class="contents"> <p class="title">Frameworks</p> <div class="select-wrapper"> <select class="select"> <option value="all">All</option> <option value="css">CSS</option> <option value="javascript">JavaScript</option> <option value="php">PHP</option> <option value="ruby">Ruby</option> <option value="python">Python</option> <option value="scala">Scala</option> </select> </div> <ul class="list"> <li data-category-type="css"> <a href="http://getbootstrap.com/" class="article"> <i class="article-icon is-bootstrap"></i> <p class="article-name">Bootstrap</p> </a> </li> <li data-category-type="ruby"> <a href="http://rubyonrails.org/" class="article"> <i class="article-icon is-ruby-on-rails"></i> <p class="article-name">Ruby on Rails</p> </a> </li> <li data-category-type="php"> <a href="https://phalconphp.com/ja/" class="article"> <i class="article-icon is-phalcon"></i> <p class="article-name">Phalcon</p> </a> </li> <li data-category-type="javascript"> <a href="https://facebook.github.io/react/" class="article"> <i class="article-icon is-react"></i> <p class="article-name">React</p> </a> </li> <li data-category-type="scala"> <a href="https://www.playframework.com/" class="article"> <i class="article-icon is-play"></i> <p class="article-name">Play</p> </a> </li> <li data-category-type="javascript"> <a href="http://aurelia.io/" class="article"> <i class="article-icon is-aurelia"></i> <p class="article-name">Aurelia</p> </a> </li> <li data-category-type="python"> <a href="http://djangoproject.jp/" class="article"> <i class="article-icon is-django"></i> <p class="article-name">Django</p> </a> </li> <li data-category-type="css"> <a href="http://www.material-ui.com/#/" class="article"> <i class="article-icon is-material-ui"></i> <p class="article-name">Material UI</p> </a> </li> <li data-category-type="php"> <a href="https://laravel.com/" class="article"> <i class="article-icon is-laravel"></i> <p class="article-name">Laravel</p> </a> </li> </ul> </div> </div> <script src="../../common/js/jquery.js"></script> <script> $(function() { $(".select").change(function() { var cateVal = $(this).val(); if(cateVal === 'all') { $(".list").find("li").show(); } else { $(".list").find("li").each(function(sort) { if($(this).data('category-type') === cateVal) { $(this).show(); } else { $(this).hide(); } }); } }); }); </script> </body> </html>
・CSS .clearfix:after { display: block; clear: both; content: ''; } .wrapper { padding: 20px; } .contents { margin: 0 auto; width: 300px; } .title { padding: 10px; font-size: 24px; font-weight: bold; text-align: center; background-color: #fff; } .select-wrapper { margin: 10px 0; text-align: right; } .select { padding: 10px; width: 100px; font-size: 14px; color: #fff; border: none; border-radius: 0; background-color: darkcyan; box-shadow: 0 1px 2px rgba(0, 0, 0, .4); cursor: pointer; -webkit-appearance: none; } .list > li { border-top: 1px #eee solid; } .article { position: relative; display: table; padding: 10px; width: 100%; background-color: #fff; table-layout: fixed; } .article-icon { display: table-cell; width: 50px; height: 50px; background-size: cover; } .article-icon.is-bootstrap { background-image: url(../img/bootstrap.png); } .article-icon.is-material-ui { background-image: url(../img/material-ui.png); } .article-icon.is-react { background-image: url(../img/react.png); } .article-icon.is-aurelia { background-image: url(../img/aurelia.png); } .article-icon.is-ruby-on-rails { background-image: url(../img/ruby-on-rails.png); } .article-icon.is-laravel { background-image: url(../img/laravel.png); } .article-icon.is-phalcon { background-image: url(../img/phalcon.png); } .article-icon.is-django { background-image: url(../img/django.png); } .article-icon.is-play { background-image: url(../img/play.png); } .article-name { display: table-cell; padding-left: 20px; width: 100%; font-size: 16px; font-weight: bold; vertical-align: middle; }
解決していない質問を解決済みにしたうえで同じ質問を投稿するのはやめましょう。 https://teratail.com/questions/250722
始めたばかりで軽い気持ちで連投してしまいました。
すみません。
回答3件
あなたの回答
tips
プレビュー