问题
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