0

Below code in thymeleaf template view is calling javascript function filter:

<select th:onchange="'filter(this, \'' + ${#lists.size(books)} + '\');'">
    <option value="all" selected="selected">All Books</option>
    <option value="fav">My Favourite</option>
</select>

But, ${#lists.size(books)} is prefixed and suffixed with &#39; as shown in the view-source:

<select onchange="filter(this, &#39;1&#39;);">
    <option value="all" selected="selected">All Books</option>
    <option value="fav">My Favourite</option>
</select>

How to remove &#39; from javascript function call in Thymeleaf?

2
  • Before checking anything else, you have \'' and then '\'. That is definitely not right. Do you mean '\' in both? Commented Jun 15, 2014 at 8:51
  • this is how we pass thymeleaf parameters to javascript. check stackoverflow.com/questions/14365746/… Commented Jun 16, 2014 at 18:57

1 Answer 1

0

&#39; is how you escape the apostrophe in tag attributes in an HTML4-compatible way. Your code is OK, and it should work perfectly.

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

Comments

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.