Hello everyone! This is my first time at webmaster-talk, I was referred by someone in web_design.reddit, for some basic javascript help.
I'm trying to learn the ins and outs of javascript and I'm making a website where I have some 800x250 images that I want to splash the center of the screen when you click the thumbnail and close again when the splash is clicked.
However, I am having some trouble with creating elements, appending them, and removing them. Here is my script:
PHP Code:
var bigImg = null; var parent = document.getElementById("content"); function makeBig(source) { bigImg = document.createElement('img'); parent.appendChild(bigImg); bigImg.style.position="absolute"; bigImg.style.left=((winWidth() - 800)/2) + "px"; bigImg.style.top=((winHeight() - 250)/2) + "px"; bigImg.src=source; bigImg.id="bigImg"; bigImg.onclick=killBig(); } function killBig() { parent.removeChild(bigImg); bigImg = null; } function showBig(source) { if (bigImg !== null) { killBig() } makeBig(source); }
And when I try it, I get this error: "parent is null" which lists this line as the offender:
PHP Code:
parent.removeChild(bigImg);
inside the killBig() function.
All help is greatly appreciated! Thanks.
|