Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change data-attribute using jquery

How can I change

<div data-300=""></div>

to

<div data-500=""></div>

using jquery?

I don't want to remove the attribute and replace it as it contains data I need I just need to change the '300' to '500'.

like image 275
Daimz Avatar asked Mar 23 '23 11:03

Daimz


1 Answers

Not generic at all, but it should do the job

var $target = $('div[data-300]'),
    oldData = $target.data('300');

$target.removeAttr('data-300').attr({ 'data-500': oldData });
like image 114
Johan Avatar answered Mar 25 '23 00:03

Johan