2026, 새로운 도약을 시작합니다.

js질문드립니다. 채택완료

Copy


var menu_count = document.getElementById('first').innerText;

var list = document.querySelectorAll("#slideCateList_s ul li");

for(let i = 1; i  15 ; i ++){

    if(list[i].innerText.includes(menu_count)){

        console.log(i);

    }

}

 





    

    

        관리

        기타

        등등

    

    



 

요렇게 했습니다.

menu_count 의 값은 "관리"로 한글 입니다.

slideCateList_s ul li 중에 "관리"가 포함되어있으면 

뭔가를 하고 싶은데 영 안됩니다 ㅠ

뭐를 잘못한걸까요?ㅠ

답변 4개

아 지금 보니깐 스와이퍼네요

스와이퍼면 transitionEnd 이벤트 사용해야 합니다.

Copy



swiper.on('transitionEnd', function() {
	console.log('now index :::', swiper.realIndex);
});

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

  var menu_count = document.getElementById('first').textContent;
                var selected = document.querySelectorAll("#slideCateList_s ul li");
                
                selected.forEach(item => {
                    //console.log(item.innerText);
                    if(item.innerText === menu_count){
                    console.log(item.innerText);
                    }
                });

요렇게도 해보았습니다.

한글을 인식 몬하는것 같습니다 ㅠㅠㅠㅠ

menu_count 는 유동적으로 변경됩니다 ㅠ

--------------------------------------

해결함

                   let menu_count = document.getElementById('first').textContent;
                $('#slideCateList_s ul li a').each(function() {
                    let txt = $(this).text();
                    let menu_count2 = menu_count.trim();
                    
                    if (txt  == menu_count2 ){
                        $(this).addClass('firston');
                    }
                });

이런식으로 해결했습니당.

trim....ㅎㅎㅎ

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

[code]

<script>
let menu_text = $('#first').text();
$('#slideCateList_s ul li a').each(function() {    
    if (menu_text.trim() == $(this).text())
        $(this).addClass('firston');
});
</script>

[/code]

댓글을 작성하려면 로그인이 필요합니다.

Copy




    

    

        관리

        기타

        등등

    

    







$('#slideCateList_s ul li a').each(function() {

    let txt = $(this).text();

    //alert(txt);

    if (txt == '관리')

        $(this).css('color', 'red');

});



로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

Copy
for(let i = 1; i  15 ; i ++){
    if(list[i].innerText.includes(menu_count)){
        console.log(i);
    }
}

 

i 값을 0으로 변경해주세요

 

요소는 0번부터 시작입니다.

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

앗! 그렇게도 해보았습니다!
중요한거는 얘가 한글을 인식을 몬하는것 같습니다 ㅠ

댓글을 작성하려면 로그인이 필요합니다.

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

로그인
🐛 버그신고