jQuery tmpl gives invalid HTML
I am using jQuery tmpl http://api.jquery.com/jquery.tmpl/, and I have <li id="${id}">
in my HTML source
But when I validate my HTML using the validator, I am getting error "Character $ is not allowed in the开发者_Python百科 value of attribute id
"
How can I solve this issue?
Place it inside a CDATA-section:
<script type="text/javascript">
/* <![CDATA[ */
$.tmpl( '<li id="${id}">something</li>', myData )
/* ]]> */
</script>
In XHTML(assuming you validate as XHTML) <script/>
is defined as #P(arsed)C(haracter)DATA , so it's contents will be parsed and the error occurs. If you place it inside a CDATA-section, the parser will ignore it.
Run validation tests on the final generated HTML, not the templates.
You'll be able to copy it using Firebug, for instance, when viewing your page.
精彩评论