I am looking to loop through all the elements with a data-speed attribute and record them. Then loop back though that array on resize to put them back to original values.
I am able to get my data-speed attributes of all elements that contain that data attribute and log them. But now I need to record them, and then add those data-attributes back to the original elements at the original value (in my resize function). Below is my html, along with how I have the JS setup so far:
// get all data-speed numbers and log them
const el = document.querySelector('.smootherReset768');
var dataAttribute = el.getAttribute('data-speed');
$('.smootherReset768[data-speed]').each(function(){
console.log($(this).data('speed'))
});
//put the values into my resize function
$(window).resize(function (){
var mq = window.matchMedia( "(max-width: 768px)" );
if (mq.matches) {
// I can change all data-speed attributes here easily
}
else {
// add code to return each element to it's original data-speed
}
}).resize();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="col-2 smootherReset768" data-speed=".8"><img src="https://assets.codepen.io/181080/home-3-900x900.jpg"/></div>
<div class="col-2 smootherReset768" data-speed="1.2"><img src="https://assets.codepen.io/181080/home-2-900x900.jpg"/></div>