I want to add data attribute to the DOM elements with jQuery but only when the $(window).width is greater that 800px. So right now I have this code and it's not working.
Note: Chrome Developer Tools doesn't report any issues in the code.
Code:
<div id="wallpaper"></div>
<div id="wallpaper-right"></div>
<div class="container"></div>
jQuery
var width = $(window).width(),
wallpapers = $("#wallpaper, #wallpaper-right"),
container = $(".container");
if ( width > 800) {
wallpapers.data("stellar-ratio") === 0.1;
container.data("stellar-ratio") === 1;
}
Desired result in HTML after adding the data attributes:
<div id="wallpaper" data-stellar-ratio="0.1"></div>
<div id="wallpaper-right" data-stellar-ratio="0.1"></div>
<div class="container" data-stellar-ratio="1"></div>