2017-09-04 9 views
-1

코드를 클릭하여 경고를 표시하려고하는데 코드가 작동하지 않는 것 같습니다. 여기 JQuery 클릭 기능이 작동하지 않습니다.

https://jsfiddle.net/MGames/9eu94Lau/1/

내 HTML입니다 :

<div class="add-cart-button-col col-right"> 
<a class="checkout-button nsg-button nsg-grad--heeb-orange" href="https://mycheckoutlinkgoeshere.com" data-query="https://linkcheckoutgoeshere.com"> 
         CHECKOUT 
        </a> 
        </div> 

그리고 여기

$(".checkout-button nsg-button nsg-grad--heeb-orange").click(function() { 
    alert('hohoho'); 
}); 

을 클릭 한 후 경고를 표시하지 않는 코드입니다 나는 여기에 코드를 작성했습니다 내가 뭘 잘못하고 있는지 찾아내는 도움을 주시면 감사하겠습니다. 고맙습니다.

편집 :이 질문은 코드에 존재하는 오류에 대한 설명을 요구하고 있기 때문에 다릅니다. 그것은 jQuery를 선택기 여러 클래스 사용

+0

https://stackoverflow.com/questions/1041344/how-can-i-select-an-element-with-multiple-classes-in-jquery –

+0

'.checkout-button nsg-button nsg-grad-- heeb-orange'! =='.checkout-button .nsg-button .nsg-grad-heeb-orange' –

답변

2

1 각 클래스 전에 .를 추가하는 것을 잊었다. (당신은 하나의 요소가 아닌 부모 - 자식의 모든 클래스를하려고으로) 모든 클래스 사이에

2.Remove 공간

작업은 니펫을 : -

$(".checkout-button.nsg-button.nsg-grad--heeb-orange").click(function() { 
 
    alert('hohoho'); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="add-cart-button-col col-right"> 
 
    <a class="checkout-button nsg-button nsg-grad--heeb-orange" href="https://mycheckoutlinkgoeshere.com" data query="https://linkcheckoutgoeshere.com">CHECKOUT</a> 
 
</div>

참조 : - How can I select an element with multiple classes in jQuery?

+0

Bro 나는 사랑해! – MGames

+0

@MGames 당신을 도울 수있어서 다행 :) :) –

2

가 공백없이 너무

$(".checkout-button.nsg-button.nsg-grad--heeb-orange") 

FIDDLE

같은 여러 기간으로 이루어진다 .. 여러 클래스와 선택 소자 중복 아니다 classNames, 모든 클래스를 가진 요소와 일치합니다.

1

그냥 사용하십시오

$("a[class='checkout-button nsg-button nsg-grad--heeb-orange']").click(function() { 
    alert('hohoho'); 
}); 
1

이 당신을 위해 작동 할 수 있습니다

$(".checkout-button.nsg-button.nsg-grad--heeb-orange").click(function() { 
    alert('hohoho'); 
}); 

우리는 여러 클래스가있을 때, 우리는 를 추가합니다. 요소에 액세스 할 때 연산자.