5

I want to add a doctype for my particular page. How can I add it using JavaScript or jQuery?

I want to add <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml2/DTD/xhtml1-strict.dtd"> using JavaScript.

fireshadow52
  • 6,298
  • 2
  • 30
  • 46
Sagar
  • 1,387
  • 2
  • 13
  • 22
  • 6
    I'm not sure if adding that dynamically will work. That would mean that the browser has to change layout modes dynamically, which means the page should be reloaded. – pimvdb Aug 23 '11 at 09:59
  • Cant you just add it at page load? – TJHeuvel Aug 23 '11 at 10:02
  • 6
    Yeah, adding a doctype with javascript (which I don't think possible anyway) would be totally pointless. The role of a doctype is to tell the browser how to interpret the page content. Adding it after the page is loaded is useless. – Matteo Mosca Aug 23 '11 at 10:03

1 Answers1

10

You cannot add a DOCTYPE to the current document(or modify it).

From the MDN-docs: doctype is a read-only property.

Dr.Molle
  • 116,463
  • 16
  • 195
  • 201