Enable this script on mobile only
Enable this script on mobile only
I have this script:
<script>
jQuery(function($)
if (!$('#et-info').length)
$('#top-header .container').prepend('<div id="et-info"></div>');
$('#et-info').prepend('<span style="margin:0 10px">NYITVATARTÁS: H-Sz 10-19, V 10-16</span>');
)
</script>
I want to enable this only on mobile.
3 Answers
3
You can us JavaScript to check the viewport width.
jQuery(document).ready(function($)
const viewportWidth = window.innerWidth;
if (viewportWidth < 640)
if (!$('#et-info').length)
$('#top-header .container').prepend('<div id="et-info"></div>');
$('#et-info').prepend('<span style="margin:0 10px">NYITVATARTÁS: H-Sz 10-19, V 10-16</span>');
);
Use the code below. This code will work on screens less than 600 screen size.
$(document).ready(function()
if ($(window).width() < 600)
jQuery(function($)
if (!$('#et-info').length)
$('#top-header .container').prepend('<div id="et-info"></div>');
$('#et-info').prepend('<span style="margin:0 10px">NYITVATARTÁS: H-Sz 10-19, V 10-16</span>');
)
);
You may change the "739" to a different number depending on the device resolution you are targeting.
if ( $(window).width() > 739)
//Add your javascript for large screens here
else
//Add your javascript for small screens here
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.