Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert value of object into span tag

Tags:

javascript

I have an object:

message: {
    text: "Here is some text"
}

I want to insert it into a span tag like this:

<span>message.text</span>

This won't print 'Here is some text', instead it will just show 'message.text' on the webpage. How can I get it to show the actual contents of the object?

like image 402
MonkeyOnARock Avatar asked Sep 13 '25 09:09

MonkeyOnARock


1 Answers

Give something id to span

<span id="span"></span>
$("#span").text(message.text);
like image 50
Nitin Dhomse Avatar answered Sep 16 '25 00:09

Nitin Dhomse