How jq uses custom attributes to modify the class of this element

I have the custom attribute "data-oddsId"" in my html

Some values of

"data-oddsId" are the same, such as data-oddsId=1 (3-4 are the same)

The

requirement is that you want to use jq to search for this data-oddsId=1 element and add class

to this element.

add class to all when clicking, remove all class when clicking

    changeClass: function (pId, id, event) {
            console.log(pId);
            console.log(id);
      
            var _self = $(event.currentTarget);
            if (_self.hasClass("act")) {
                _self.removeClass("act")
            } else {
                _self.addClass("act")
            }
        },
Mar.09,2021

take a look at css selector

$('div[data-oddsld="1"]').addClass('')


 $("[data-oddsId='1']").addClass() 

Click event. Delete if there is class, and add

if there is no class.

toggleClass


$('div[data-oddsld="1"]').click(function(){
    $(this).toggleClass('active')
})
Menu