Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding data to span tag dynamically

I have a span tag inside with there is some html code to create some corners and other things. Now using javascript i want to add some captions to it.The constraint is the original content of span should not get overwritten.

Eg

<span>  <!-some more complicated html code </span>

Now i want to add caption in span so that span should look like

<span> NEW CAPTION <!-some more complicated html code </span>

How can i do it?

document.getElementById.innerHtml = "NEWCAPTION" + document.getElementById.innerHtml 

is this correct?

like image 729
Sanket Avatar asked Oct 14 '22 21:10

Sanket


1 Answers

You will need to give the span an ID if you going to do it that way. Also the innerHtml should be innerHTML

eg.

<span id="mySpan">  <!-come more complecated html code </span>

document.getElementById('mySpan').innerHTML = "NEWCAPTION" + document.getElementById('mySpan').innerHTML
like image 125
Cubed Eye Avatar answered Oct 29 '22 17:10

Cubed Eye