Is it possible to put the contents of a "thymeleaf object" inside a "variable" in HTML?

1

To contextualize:

I have a "log" object, which was declared in an HTML page through thymeleaf:

<html xmlns:th="http://www.thymeleaf.org" th:include="layout :: page">
  ...
 <form class="form-inline" action="#" th:action="@{'log/'}" th:object="${log}" method="post">

In some part of the code the content of this object, which is nothing more than a string of text, is displayed:

<p th:utext="${log.content}">Log content</p>

Content:

1. a
2. b
3. c
...

My question:

Is it possible to put this content inside a variable, and then use it inside an .js?

Something like:

HTML:

<input type="hidden" th:value="${log.content}" >

Js:

var aux = $('input');
document.getElementById('content').innerHTML = aux.value;

My goal is to handle this " log.content " out of HTML, is it possible?

    
asked by anonymous 06.08.2018 / 16:42

1 answer

0

Since inside this input will have a value brought by the th: value="$ {log.content}" . You can get the value in a number of ways, by id , by class , usually with Javascript or jQuery / p>

var valorInput1 = $('input:hidden').val(); // jQuery
console.log(valorInput1);                 // pega o valor do input que está com display none

var valorInput2 = document.getElementById('valorDoInput').value; // Javascript
console.log(valorInput2); // pega o valor do input com um id
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><inputtype="hidden" th:value="${log.content}" value="10">

<input type="hidden" id="valorDoInput" th:value="${log.content}" value="20">
    
06.08.2018 / 17:06