Trying to get code validated - recommends I remove <div>'s but why?

here is the code:

<div style="width: 225px; height: 155px; float: left; height: 16px; background-color: #000000; color: #FFFFFF; margin-left: 0px; margin-bottom: 0px; font-size: small; padding-left: 0px;">
	&nbsp;<img alt="" src="images/news.png" height="16" width="222" /><div style="width: 225px; height: 155px; float: left;"><script type="text/javascript">// <![CDATA[if(document.layers){document.write('<ilayer id="ns4div" width="'+swidth+'" height="'+sheight+'" bgcolor='+sbcolor+'><div id="ns4div1" width="'+swidth+'" height="'+sheight+'" onmouseover="sspeed=0;" onmouseout="sspeed=rspeed"></div></ilayer>')}
if(document.getElementById||document.all){document.write('<div style="position:relative;overflow:hidden;width:'+swidth+'px;height:'+sheight+'px;clip:rect(0 '+swidth+'px '+sheight+'px 0);background-color:'+sbcolor+';" onmouseover="sspeed=0" onmouseout="sspeed=rspeed"><div id="iens6div" style="position:relative;width:'+swidth+'px;"></div></div>');} // ]]></script>

here is the error:

end tag for element “div” which is not open
The Validator found an end tag for the above element, but that element is not currently open. This is often caused by a leftover end tag from an element that was removed during editing, or by an implicitly closed element (if you have an error related to an element being used where it is not allowed, this is almost certainly the case). In the latter case this error will disappear as soon as you fix the original problem.

any ideas?

You’ve got a stray </div> the one highligted by the validator is most likely the stray one. A couple of tips for HTML

  • Indent each level of divisions
  • At the end of each division have it so that it’s like:
</div><!-- end of division [division_name] --> 

It will help you keep track of where divisions start and end

yes, that would be logical to assume, but if you take a close look at my html, you’ll see that I do need those </div>'s, both of them. I’ve tried removing one and both of them, but then I have an unclosed div or two. here is a slimmed down version of the html.

</div><!-- end of division [division_name] --> 

It will help you keep track of where divisions start and end

yes, that’s a good suggestion.

You have JavaScript in the HTML and the validator is trying to interpret the JavaScript AS HTML.

If you expect the validator to be able to properly validate the HTML then you should move the JavaScript into a separate file or at least not use inline JavaScript to write HTML the 20th century way where it creates a mess that the validator can’t interpret correctly.

I think also that css belongs in a separate file as well