maimon
maimon

Reputation: 43

I want to add the class just in the clicked span

when I tried to use jQuery it changes every span with the same class but I don't want to add an id for each span

$(".bay-btn").click(function (e) { 
        e.preventDefault();
        $(".bay-btn").addClass('bay-btn-clicked');
    });

I want to add a class to the clicked span without the unclicked yet

        <div class="type1 types">
            <div class="img-con"><img src="/src/shop/imgs/black-sh.jfif" alt=""></div>
            <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Eius esse consequatur magnam exercitationem quisquam.</p>
            <span class="cost">10$</span>
            <span class="bay-btn">Bay</span>
        </div>
        <div class="type2 types">
            <div class="img-con"><img src="/src/shop/imgs/red-sh.jfif" alt=""></div>
            <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Eius esse consequatur magnam exercitationem quisquam.</p>
            <span class="cost">10$</span>
            <span class="bay-btn">Bay</span>
        </div>

Upvotes: 3

Views: 53

Answers (1)

Daniil R&#245;bnikov
Daniil R&#245;bnikov

Reputation: 63

It seems that you misspelled the class name ".pay-btn" and ".bay-btn" in jQuery, so the code would be:

$(".pay-btn").click(function (e) { 
        e.preventDefault();
        $(".pay-btn").addClass('pay-btn-clicked');
    });

And dont forget to update the class names in HTML file as well: bay-btn -> pay-btn

Upvotes: 2

Related Questions