I have the following HTML code that displays an image:
<div> <img id="wm01" alt="PP" title="PP" u="image" src="theImages/wm01.jpg" /> </div>
What I'm trying to do is display a different image depending on the screen size. Therefore, first hide the image using CSS:
#wm01 { display: none; }
And then in my BODY I will add the following code:
var w = window, d = document, e = d.documentElement, g = d.getElementsByTagName('body')[0], x = w.innerWidth || e.clientWidth || g.clientWidth, y = w.innerHeight|| e.clientHeight|| g.clientHeight; if (x<568) { //alert(x); document.getElementById("wm01").src="theImages/wm01_app.jpg"; document.getElementById("wm01").style.display = "block"; } else { document.getElementById("wm01").src="theImages/wm01.jpg"; document.getElementById("wm01").style.display = "block"; }
The image does not appear on the screen of any size. How can i fix this?
source share