isotope 필터 기능 질문드립니다.

조회수 377회

이렇게 필터를 만들었습니다. 현재는 클릭할 때만 작동이 되는데 처음 화면이 로드 될 때 class에 selected값이 있는 항목을 보여주고 싶은데 가능한가요?

<ul id="filter-buttons">
                <li><a href="#" data-filter="food" class="selected">식품</a></li>
                <li><a href="#" data-filter="kids" >KIDS</a></li>
                <li><a href="#" data-filter="goods" >굿즈</a></li>
                <li><a href="#" data-filter="love" >반려동물</a></li>
            </ul>
<script>
            var posts = $('.post');
            posts.hide()



                $('#filter-buttons li a').click(function(){
                    var customType = $(this).data('filter');

                    posts
                        .hide()
                        .filter(function(){
                            return $(this).data('cat') === customType;
                        })
                        .show();
                })


            </script>

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)