0

Just a quick validation question, I get:

document type does not allow element "div" here

And my code:

  $('#wrapper').prepend('<div id="slider"></div>');

It's just a JS stuff, how do I handle this?

8
  • Where in the document is this located? Commented Mar 11, 2013 at 22:45
  • Where are you getting that error, in the console or on W3C ? Commented Mar 11, 2013 at 22:45
  • What type of element is #wrapper? Commented Mar 11, 2013 at 22:46
  • @ryan It's located just before closing the body tag. Commented Mar 11, 2013 at 22:49
  • 2
    What is the DOCTYPE, what type of element is #wrapper, and what type is its parent node. A relevant snippet of the markup would help. Commented Mar 11, 2013 at 22:51

1 Answer 1

2

I can't think of any time you would get that error in the middle of a piece of JavaScript unless you are using XHTML, in which case the short answer is: Stop using XHTML, start using HTML 4 or 5.

The reason you get the error is described in the XHTML 1.0 specification:

In XHTML, the script and style elements are declared as having #PCDATA content. As a result, < and & will be treated as the start of markup

The latest version of the XHTML Media Types note provides work–arounds:

DO use external scripts if your script uses < or & or ]]> or --. DO NOT embed a script in a document if it contains any of these characters.

and

If you must embed the content, the following patterns can be used:

<style>/*<![CDATA[*/
...
/*]]>*/</style>

This is all rather a lot of effort, and just switching to HTML is a simpler option. Browsers are designed for HTML and their XHTML support is provided as an afterthought. If you get any benefits from XHTML it will be from using it with server side tools as part of your publishing process … and not many people are doing that.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.