get data attribute value onclick link / button

后端 未结 6 1957
攒了一身酷
攒了一身酷 2021-02-20 11:50
Daily
            

        
6条回答
  •  后悔当初
    2021-02-20 12:20

    You can get attribute values of an element using the attr in jquery like

    $('.home').on('click', function() {
    
        var d = $(this).attr('data-datac');      
        alert(d);   
    });
    

    F.Y.I

    If you will use id's as selector you can only get one element while on a class you can get reference all the elements containing that class

提交回复
热议问题