티스토리 뷰

if($('span').hasClass('fa fa-crosshair fa-lg'))

span당신이 그것을 기대하고있는 것을 표적으로하지 않을 것 입니다.

당신은 원했다

if($('span',this).hasClass('fa fa-crosshair fa-lg'))

클릭 한 범위의 하위 범위를 타겟팅하려면

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

이 예제를 실행하면 도움이되기를 바랍니다.

$(document).ready(function() {
      // My example to trigger the click on buttons..
        $("button > span > span").click(function(){
            
                alert("Button was clicked");
                    
                        if (
                              //$(this).hasClass('fa') && <-- You don't need it, both have it
                                    $(this).hasClass('fa-crosshairs') &&
                                          $(this).hasClass('fa-lg')
                                              ) {
                                                    alert('My button has active class');
                                                        } else {
                                                              alert('Ops..');
                                                                  }
                                                                    });
                                                                    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    
    <!-- Unclicked -->
    <button class="easy-button-button leaflet-bar-part leaflet-interactive add-markers-active" title="Vis crosshair">
        <span class="button-state state-add-markers add-markers-active">
                <span class="fa fa-crosshairs fa-lg">click me</span>
                    </span>
                    </button>
                    
                    <!-- Clicked -->
                    <button class="easy-button-button leaflet-bar-part leaflet-interactive remove-markers-active" title="Fjern crosshair">
                        <span class="button-state state-remove-markers remove-markers-active">
                                <span class="fa fa-undo">clicked</span>
                                    </span>
                                    </button>
스 니펫 확장



출처
https://stackoverflow.com/questions/39920113
댓글
공지사항
Total
Today
Yesterday
«   2025/06   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30