PDA

View Full Version : Run JS On Mobile Only - not working



mat420
09-20-2015, 03:39 PM
Any idea? Im not too good with code. Code works fine when I just put the code in jquery.js (yeah i know its javascript), right before </body>. Thank you.

<head>
<link rel='stylesheet' media='screen and (max-device-width: 640px)' href='jquery.js'>
</head>


jquery.js


function myFunction() {
var container = document.getElementById('container'),
divs = container.getElementsByTagName('div'),
tmpdiv = document.createElement('div'),
order = [3, 2, 1];

for (var i = 0; i < order.length; i++) {
tmpdiv.appendChild(document.getElementById('div' + [order[i]]));
}

container.parentNode.replaceChild(tmpdiv, container);

}
window.onload = myFunction();

Beverleyh
09-20-2015, 04:28 PM
Might help http://stackoverflow.com/questions/15823137/call-external-js-file-based-on-media-screen-value

mat420
10-08-2015, 06:29 PM
thanks bev!