ilyo
ilyo

Reputation: 36411

what is the most straightforward way of writing the content of a variable to page?

I have a <p></p> and I want to put a text inside it a text that a JS variable holds, is it possible to put a <script> inside the <p> and just write it there, without using any kind of DOM searching (not even innerHTML)?

Upvotes: 0

Views: 32

Answers (1)

Baz1nga
Baz1nga

Reputation: 15579

<p>
<script>
var theVariable="this has some content";
document.write(theVariable);
</script>
</p>

hope that helps and is what you wanted.

Demo

Upvotes: 2

Related Questions