jarosik
jarosik

Reputation: 4564

Thymeleaf and jQuery quotes fails

I'm trying to generate a valid span tag via jQuery:

$("#commentsSection").append("<span class='myClass'>");

$("#commentsSection").append("</span>");

I'm using Spring Boot and Thymeleaf and such html won't render due to:

SyntaxError: missing ) after argument list
$("#commentsSection").append("<span class="myClass">");

Should I esape quotes somehow?

Upvotes: 0

Views: 190

Answers (3)

Benjamin Sch&#252;ller
Benjamin Sch&#252;ller

Reputation: 2199

If your javascript is directly in the html file then surround it with a CDATA-Block so thymeleaf doesn't try to render it.

<script>
  // <![CDATA[
  .
  . your code
  .
  // ]]>
</script>

Upvotes: 1

Ashish Taldeokar
Ashish Taldeokar

Reputation: 65

You need to put escape char like this,

"<span class=\"myClass\">"

Hope it works!

Upvotes: 0

rrk
rrk

Reputation: 15875

Escape the quotes or use ' single quote inside.

$("#commentsSection").append("<span class='myClass'>");

or

$("#commentsSection").append("<span class=\"myClass\">");

Upvotes: 0

Related Questions