Showing a div only on mobile devices using jQuery

六月ゝ 毕业季﹏ 提交于 2021-01-28 12:14:47

问题


i have a phone number div.when it is clicked, it will trigger a call,so i want to display this div only on mobile devices.for that i have assigned display none to the div initially and i am trying to show the div on mobile devices using jQuery like below

$(document).ready(function () {
    if($(window).width() <= 480) {
        $('#phone-number').show();
    }
});

But it doesn't work.i didn't know what is wrong with this ,please someone help me in this issue


回答1:


Can you also put your code in $(window).resize handler like below:

$(window).resize(function() {
    if($(window).width() <= 480){
        $('#phone-number').show();
    }
});

Also make sure that you are giving correct id #phone-number



来源:https://stackoverflow.com/questions/34465942/showing-a-div-only-on-mobile-devices-using-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!