EDIT
Ok I noticed I didn't answer your question.
The error that you are getting is because of the XHTML
. XHTML has certain rules you have to follow. In the case of the error you are getting you need to change your <script></script>
block to be like so:
<script type="text/javascript">
//<![CDATA[
$(document).ready(function() {
$("ul.dropdown li").hover(function() {
$(this).addClass("hover");
$('ul:first', this).css('visibility', 'visible');
$("#inbox").html("<li><a href=\"http://example.com\">Message1</a></li>");
//$("#inbox").append("<li><a href=\"http://example.com\">Message2</a></li>");
}, function() {
$(this).removeClass("hover");
$('ul:first', this).css('visibility', 'hidden');
});
$("ul.dropdown li ul li:has(ul)").find("a:first").append(" >");
});
//]]>
</script>
Notice the //<![CDATA[
and its closing //]]>
this tells the page not parse whatever is inside the CDATA as XML.
This is only important when you have inline <script></script>
. This error does not happen when you have it as an external .js
file.
Here is a good read on the matter: http://javascript.about.com/library/blxhtml.htm
There is no problem with your html appending.
I added the empty()
method so that the submenu doesn't keep growing everytime you hover over it.
...
$('#inbox').empty()
.append("<li><a href=\"http://example.com\">Message1</a></li>")
.append("<li><a href=\"http://example.com\">Message2</a></li>");
...
if you want to still use the .html()
this is how it would be used:
...
$('#inbox').html("<li><a href=\"http://example.com\">Message1</a></li>" +
"<li><a href=\"http://example.com\">Message2</a></li>");
...