Updating the value of data attribute using jQuery

后端 未结 4 2332
长情又很酷
长情又很酷 2020-12-08 18:38

I have the following HTML code:


    \"No\"

        
4条回答
  •  -上瘾入骨i
    2020-12-08 19:06

    $('.toggle img').each(function(index) { 
        if($(this).attr('data-id') == '4')
        {
            $(this).attr('data-block', 'something');
            $(this).attr('src', 'something.jpg');
        }
    });
    

    or

    $('.toggle img[data-id="4"]').attr('data-block', 'something');
    $('.toggle img[data-id="4"]').attr('src', 'something.jpg');
    

提交回复
热议问题