3

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?

2 Answers 2

12
<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.

Sign up to request clarification or add additional context in comments.

Comments

-1

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

4 Comments

Comments, if the XHTML is processed as XHTML, will comment out the script so it will not run. Do NOT use them for this.
David, I just tested in Firefox 3 with a XHTML 1.0 Strict (fully validating) page containing : <script type="text/javascript"> <!-- alert("foo"); --> </script> You're simply wrong.
Did you serve the document as application/xhtml+xml? I'm betting not. If you serve it as text/html then it will be processed as HTML not XHTML. The rules for HTML are not the same as those for XHTML.
I stand corrected. When served as XML (note, this is not required to be valid XHTML), the script will not run.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.