How to always listen to window.width() and load different HTML codes based on the width values? I'm using window.width() and replaceWith().
It's only works when I open the page and not working when I resizing my browser window.
My code inside my html file:
var width;
$(window).resize(function() {
width = $(window).width();
if (width < 768) {
$("#the_dropdown").replaceWith("<p>Less than 768</p>");
} else {
$("#the_dropdown").replaceWith("<p> More than 768</p>");
}
});
$(window).trigger('resize');
Another question, does replaceWith() suitable for situation that involves long HTML codes (more than 1 line)?
I've already done some sets of HTML codes based on specific window's width and I want to put it accordingly inside my #the_dropdown div.
@mediaqueries : w3schools.com/cssref/css3_pr_mediaquery.aspresponsive design.window.matchMediaand any polyfill to support older browsers if needed developer.mozilla.org/en-US/docs/Web/API/Window.matchMedia