티스토리 뷰

728x90

        const searchBox = document.querySelector('#search-box');
        const cssCount = document.querySelector('.count');
        const cssDesc = document.querySelector('.desc');
        const cssList = document.querySelector('.list');

        cssProperty.map((ele, idx) => {
            cssCount.innerText = "전체 목록 갯수 : " + (idx + 1) + "개";
            cssList.innerHTML += "" + ele.name + "";
        })

        searchBox.addEventListener("keyup", () => {
            const searchWord = searchBox.value;
            findProp(searchWord);
        })

        function findProp(searchProp) {
            const targetData = cssProperty.find((data) => data.name === searchProp)

            //찾는 데이터가 없을 때
            if(targetData == null){
                cssDesc.textContent = "해당 속성은 존재하지 않습니다. 다시 검색해주세요!";
                return
            }
            cssDesc.innerHTML = targetData.desc;

        }
        document.querySelectorAll('.list span').forEach( () => addEventListener('click', (el) => {
            const listProp = el.target.innerText;
            findProp(listProp);
        }));
320x100

'Script Sample > SearchEffect' 카테고리의 다른 글

SearchEffect06 - sort( ), reverse()  (0) 2022.02.21
SearchEffect05 - filter()  (0) 2022.02.21
SearchEffect03 - charAt()  (0) 2022.02.21
SearchEffect02 - includes()  (1) 2022.02.07
SearchEffect01 - indexOf()  (7) 2022.02.07
댓글
© 2022 WonSeok, All rights reserved