Im searching to produce a symptom in wordpress loop. if no image then image box (.thumbHome)

this really is during my function.php

function getThumbImages($postId) {
$iPostID = get_the_ID();
$arrImages =& get_children('post_type=attachment&post_mime_type=image&post_parent=' .   $iPostID );
if($arrImages) {
    $arrKeys = array_keys($arrImages);
    $iNum = $arrKeys[0];
    $sThumbUrl = wp_get_attachment_thumb_url($iNum, $something);
    $sImgString =  '<img src="' . $sThumbUrl . '" alt="thumb Image" title="thumb Image" />';
echo $sImgString;}
else {
echo '<script language="javascript">noImage()</script>';
}
}  

And my javascript:

window.onload = noImage();
 function noImage(){
document.getElementByClassName('.thumbHome').css.display = 'none';
}

I attempted:

window.onload = noImage();
function noImage(){
$('.thumbHome').addClass('hide');
} 

RESULT: class hide put into all loop

I cant decipher it one other way, since im still new in coding.

thx

Well to begin with, you won't want to call these characteristics on window.onload. That will immediately set all class cases of .thumbHome to hidden with no conditions.

Here's an easy method to fix this problem. You will find most likely more intricate ways, but this is effective.

Inside your primary loop, add a special id to every .thumbHome div in line with the image id. So like:

echo '<div class="thumbHome" id="thumb-' . $iNum . '"> ... </div>';
// or you could you use the post ID, doesn't matter, as long as you are consistent

Your else conditional (for whether there is a thumbnail) might be transformed to:

else {
    echo '<script type="text/javascript">noImage("#thumb-' . $iNum . '")</script>';
}

as well as your js function might be:

function noImage(var){
    $(var).hide();
}

This isn't necessary the easiest method to do that, it is simply the easiest way using the situtation you are in now.