Reputation: 17185
I have some code that looks like this:
document.getElementById("error").style.display = 'block';
and when this happens I also want to display the error that is supposed to be shown which is stored in another JS variable. How can I add the value of that variable to the div which has id="error"
Thanks!
Upvotes: 21
Views: 74398
Reputation: 9037
var displayDiv = document.getElementById('error');
displayDiv.style.display = 'block';
displayDiv.innerHTML = yourVariable;
Upvotes: 3
Reputation: 1891
document.getElementById('error').innerHTML = variable
(using jQuery would be easier.
Upvotes: 2
Reputation: 207521
var errorDiv = document.getElementById("error");
errorDiv.innerHTML = yourVariable;
errorDiv.style.display = 'block';
Upvotes: 2
Reputation: 1425
document.getElementById("error").innerHTML = my_js_variable;
Upvotes: 4
Reputation: 34224
var errorMsg = "<p>Example error message</p>"
document.getElementById("error").innerHTML = errorMsg
Upvotes: 35