Change id of DIV on mobile

Instead of hardcoding widths, you can use different ways that javascript provides to detect the device (What’s the best way to detect a ‘touch screen’ device using JavaScript?)

The issue which you may face if you replace the ID like this:

suppose your javascript is loaded before the HTML rendered, and later you change the Id, then events on that may not work, and you may land up solving that issue. and many more issues may come.

If you don’t want to get into these complications, then I would suggest. just before your div is getting rendered(before you add your html code of this carousel), set the ID at that time itself, instead of replacing the ID later.

I mean, first time your html is getting added to DOM, it should have correct ID.

but if you want your code to work, then Chris has answered it in comments, you have not assigning to the variable.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top