Why it will not be confirmed (jquery problem)?

On my site, I use the jquery cycle plugin for a slide show with a pager. This example: http://malsup.com/jquery/cycle/pager.html

So, in the head of my document, I have a script similar to:

<script type="text/javascript">
$('#s4').before('<div id="nav">').cycle({ 
    fx:     'turnDown', 
    speed:  'fast', 
    timeout: 3000, 
    pager:  '#nav' 
});
</script>

My document type is XHTML Strict.

When I try to check the page, I get the following errors: "the document type does not allow the div element here" and the "end tag for the div" is omitted, but OMITTAG NO was specified "because the div tag is not closed.

Is there a way to use jquery and make it validate?

+3
source share
3 answers

, , , , XHTML (, "<" ..), CDATA XHTML (- XML). HTML ( , "--" ) SCRIPT, valid JavaScript. , HTML, "CDATA", JavaScript:

<script type="text/javascript">
//<![CDATA[
$('#s4').before('<div id="nav">').cycle({ 
    fx:     'turnDown', 
    speed:  'fast', 
    timeout: 3000, 
    pager:  '#nav' 
});
//]]>
</script>

:

+8

HTML script, .

<script type="text/javascript">
<!--
$('#s4').before('<div id="nav">').cycle({ 
    fx:     'turnDown', 
    speed:  'fast', 
    timeout: 3000, 
    pager:  '#nav' 
});
//-->
</script>
+8

You could get rid of the errors by doing:

$('#s4').before('<' + 'div id="nav">').cycle({ ...

This should force the validator to detect any HTML inside the script tag. I - I would have lived with an error, knowing that this is a problem with the validator, and not with my code.

+1
source

Source: https://habr.com/ru/post/1708658/


All Articles