a tech kat
a tech kat

Reputation: 71

How can I display a variable content in HTML?

It's already my 9th day of learning how to code! #excitement

Let's say I have a title

<h1 id="title">TEST </h1>

And I have the variable

<script type="text/JavaScript">
    var content=$("#title).html();
</script>

How do I now get the var content displayed in let's say a new paragraph? I was trying something like this:

<p id="test">  <p>
    <script type="text/javascript">
        $("#test").html(content);
    </script>

Thanks!

PS: I've seen things using "Element.innerHTML", but that didn't seem to really fit my problem, or I just didn'T get it. The question asker didn't provide an example.

Upvotes: 1

Views: 3651

Answers (1)

Bharat
Bharat

Reputation: 2464

Simple way you can do this, see below code

$(document).ready(function(){
    $("#test").text($(".title").html());
});
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>

<h1 class="title">TEST </h1>
<p id="test">  <p>

Upvotes: 4

Related Questions