If I log data to the console this code is working fine, but for some reason the jQuery selector won’t work, although it does work when it’s not in the setInterval.
var refreshId = setInterval(function() {
if ($('body').width()<=979) {
console.log('small');
$('.switch-type').attr('data-type', 'vertical');
} else {
$('.switch-type').attr('data-type', 'horizonal');
console.log('big');
}
}, 1000);
Update:
Code works fine, it’s just that jQuery mobile has already done it’s think by the time this executes.
You can try to log to the console
In that way you know if the DOM element exists when you are trying to access it. I recently had a problem like this, then I realized that the element wasn’t in the DOM when I was trying to use it.