Home > Software engineering >  jQuery get data to a div
jQuery get data to a div

Time:03-22

I'm trying to show users their screen resolution in a specific div on my page. I've got it working with a button and an alert:

function getResolution() {
   alert("Your screen resolution is: "   Math.floor(screen.width * window.devicePixelRatio)   "x"   Math.floor(screen.height * window.devicePixelRatio));}

But I want that to just show up in a div instead of using a button and alert. What I've tried:

$(function(){
$('#info').show("Your screen resolution is: "   Math.floor(screen.width * window.devicePixelRatio)   "x"   Math.floor(screen.height * window.devicePixelRatio));
});

CodePudding user response:

$('#info').show()

this code will let #info display if you want to set content, try this:

$('#info').text("Your screen resolution is: "   Math.floor(screen.width * window.devicePixelRatio)   "x"   Math.floor(screen.height * window.devicePixelRatio))

check #info z-index is bigger than others

  • Related