Tylor
Tylor

Reputation: 1413

How to get this line of jQuery to validate as XHTML strict

I have this bit of jQuery at the top of my page (used for a simple image carousel):

$(document).ready(function(){   
    $("#slider").easySlider({
        prevText:'<div id="backarrow">Back</div>',
        nextText:'<div id="nextarrow">View Other Projects</div>',
        orientation:'horizontal'
    });
});

however, I can't get it to validate XHTML strict:

Line 12, Column 33: document type does not allow element "div" here

Any ideas?

Upvotes: 3

Views: 1895

Answers (2)

ceejayoz
ceejayoz

Reputation: 180014

<script type="text/javascript">
/* <![CDATA[ */
$(document).ready(function(){   
    $("#slider").easySlider({
            prevText:'<div id="backarrow">Back</div>',
            nextText:'<div id="nextarrow">View Other Projects</div>',
            orientation:'horizontal'
    });
});
/* ]]> */
</script>

This tells the validator to interpret the script as character data, not markup, and thus it won't parse the structure of the CDATA block. Wikipedia has more info.

Upvotes: 12

Matthew Flaschen
Matthew Flaschen

Reputation: 284806

It has nothing to with JQuery. Just surround the JS with comments (CDATA as ceejayoz gave should work too).

Upvotes: -1

Related Questions