I'm very new with JS however I have a fairly basic yet sound understanding of HTML and CSS. I've been working on a joke website of sorts and I want to stretch a picture to fill the entire web browser based on how large the browser window is, my first thought was doing it in JS so I got to work. So far I have this short bit of code on the JS side of things.
var x = window.innerWidth;
var y = window.innerHeight;
document.getElementById("pic1").height = y;
document.getElementById("pic1").width = x;
I don't have anything in my stylesheet outside of hiding an audio tag and for the HTML side of things I'll only add what's pertinent
...
<img src="images/1.jpg" id="pic1">
...
When I open the page I get an error in my JS console saying "Uncaught TypeError: Cannot set property 'height' of null" on line 3 which to me means that my JS can't find an element with the ID of "pic1" but I obviously have an image with an ID of "pic1" or at least that's what I see.
TL;DR: OP is a dumbass and can't figure out how to resize an image with JS.
Sorry for not responding to everyone I've been busy with essays but thanks for all the input I'll try all of these solutions sometime tonight if I can put aside the time and report back on how they worked, again thank you to everyone that contributed.
I just tried that and it gives me the same error I think I'll start looking into sgtawesomesauce's suggestion of using JQuery. Also you're correct in your reply to kreestuh I am aiming for a dynamic resizing of the picture.
@kreestuh I think I'll have to settle for this as a quick and dirty solution. I can't believe I had forgotten the background property in CSS.
No problem. Perfectly sized background images is a problem we have to solve fairly often for clients but oftentimes there just isn't a perfect option unless you want to spend twice the amount of time (read:cash lol). Background-size:cover and/or 100% will usually get you close enough in most sizes.