Reputation:
How to assign a variable value in javascript
and use it in html
?
My javascript
code:
function validateUrl() {
var displayButton = "Yes";
}
My html
code:
<c:if test="${displayButton == 'Yes' "
</c:if>
How can i use a javsacript
variable in my html
?
Upvotes: 0
Views: 71
Reputation: 919
This is not HTML, it is a JSTL-Tag.
The code <c:if
will be evaluated by the server (glassfish/tomcat) while producing the HTML which will be provided to the browser.
The JavaScript code runs in the browser. There is no (simple) way to use JavaScript values to manipulate HTML-rendering.
HTML itself isn't able to work with JavaScript-variables, so the only way is, to set a variable in JavaScript and use the value with JavaScript.
Upvotes: 1
Reputation: 311
You can set data using jquery and $("#display-button").data("key", "Yes")
you can read the data out using $("#dispaly-button").data("key") -> returns "Yes"
Upvotes: 0