I'm trying to change the id of a div on mobile vs desktop.
Using
$(document).ready(function() {
var bodyWidth = $('body').width();
if (bodyWidth > 320 && bodyWidth < 400) {
document.getElementById("carousel-example");
if (div) {
div.setAttribute("id", "carousel-mobile");
}
}
if (bodyWidth > 768 && bodyWidth < 1024) {
document.getElementById("carousel-mobile");
if (div) {
div.setAttribute("id", "carousel-example");
}
}
if (bodyWidth > 1224) {
document.getElementById("carousel-mobile");
if (div) {
div.setAttribute("id", "carousel-example");
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
And it's not working, can anyone help?