how can i change the DOCTYPE

mana picture mana · Jun 30, 2010 · Viewed 19.7k times · Source

anyone here know how i can dynamically change the doctype with javascript?

i have tried with this function,

document.doctype('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">'); ,

but it does not work.

Answer

Akash Saikia picture Akash Saikia · Jan 25, 2013

I hope this one might help some of you ( Tested in Console and it changes actual DOCTYPE)

var newDoctype = document.implementation.createDocumentType(
 'html',
 '-//W3C//DTD XHTML 1.0 Transitional//EN',
 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtdd'
);

document.doctype.parentNode.replaceChild(newDoctype,document.doctype);