I have multiple elements that'll have the same data attributes but with different values, how can I get jQuery to change the value?
Below is some example HTML.
<div data-one="test" data-two="test2"></div>
<div data-one="testing" data-two="hello"></div>
<div data-one="yo" data-two="test3"></div>
By default, I would like to the value of div to be data-one but then when the class active is on the body tag, I would like it to change all the values to the data-two value.
I thought about storing values as a variable which would be easier although the divs don't have any ID's and they're scattered around in the DOM which makes it difficult.
So far I had this:
if($('body').hasClass('active')) {
$('div').html($(div).data('two'));
}
<div>s don't have values..val()is for form elements.