function ChangePosit(x) { if (x.matches) { // If media query matches function switchElements($ele1, $ele2) { // clone elements and their contents var $ele1Clone = $ele1.clone(), $ele2Clone = $ele2.clone(); // switch places $ele1.replaceWith($ele2Clone); $ele2.replaceWith($ele1Clone); } setTimeout(function(){ // cache elements var $ele1 = $('#sbit'), $ele2 = $('#sbi'); switchElements($ele1, $ele2); }, 20); } else { function switchElements($ele1, $ele2) { // clone elements and their contents var $ele1Clone = $ele1.clone(), $ele2Clone = $ele2.clone(); // switch places $ele1.replaceWith($ele2Clone); $ele2.replaceWith($ele1Clone); } setTimeout(function(){ // cache elements var $ele1 = $('#sbi'), $ele2 = $('#sbit'); switchElements($ele1, $ele2); }, 20); } } var x = window.matchMedia("(max-width: 900px)") ChangePosit(x) // Call listener function at run time x.addListener(ChangePosit) // Attach listener function on state changes </script>
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter