Hello,

I recently started to dip my toes into the DOM and Javascript but I ran into a problem. I get this error:

parent has no properties
[Break on this error] if(parent.lastChild == targetElement){
Here's the javascript:
Code:
function insertAfter(newElement, targetElement){
	var parent = targetElement.parentNode;
	if(parent.lastChild == targetElement){
		parent.appendChild(newElement);
	}else{
		parent.insertBefore(newElement, targetElement.nextSibling);	
	}
}

function contactCheck(){
	if(!document.getElementById('contactform')) return false;
	function okimg(where){
		var okimg = document.createElement('img');
		okimg.setAttribute('alt', 'Correct');
		okimg.setAttribute('src', '/media/img/form_good.gif');
		okimg.setAttribute('class', 'ok');
		okimg.setAttribute('id', where + 'ok');
		insertAfter(okimg, where);
	}
	if(document.getElementById('c-name')){
		document.getElementById('c-name').onchange = function(){
			if(document.getElementById('c-name').value != ''){
				okimg('c-name');
			}
		}
	}
}
The html involved
Code:
<dd>
	<input id="c-name" class="text" type="text" value="" name="c-name"/>
</dd>
I'm kinda stuck on this, I don't understand how the dd can't be the parentNode?