I have a contrast switcher which fails validation. I've read When is a CDATA section necessary within a script tag? and tried to both escape the characters and use CDATA but I'm still getting validation errors for both.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<script type="text/javascript">
$(document).ready(function(){
// DRY wrapper function
function appendStyleSheet() {
$('head').append('<link rel="stylesheet" href="{site_url}css/high-contrast.css" type="text/css" id="hc_stylesheet"/>');
}
// append the style sheet on load if the cookie is set to true
if ($.cookie('high_contrast_momentum') == 'true') {
appendStyleSheet();
}
$("#contrast-btn a").click(function () {
if ($.cookie('high_contrast_momentum') != 'true') {
appendStyleSheet();
$.cookie('high_contrast_momentum', 'true', {expires:365}); // set the cookie to true
}
else {
// remove the high-contrast style
$("#hc_stylesheet").remove();
$.cookie('high_contrast_momentum', 'false');
}
});
});
</script>
The validation error I'm getting is: document type does not allow element "link" here