user691175
user691175

Reputation: 1

Unable to render the html tags dynamically

I am using innerHTML property to insert a span into a div. But the span is not getting displayed immediately on the page. however if we use alert function immeditely after the innerHTML statement, the span is getting displayed. Please help Thanks in advance,

Regards,

Robin

Upvotes: 0

Views: 234

Answers (1)

Ortiga
Ortiga

Reputation: 8824

Try using DOM method:

// Create the span
var span = document.createElement('span');

//set attributes you want
span.setAttribute('id','mySpanId');

//Then append as child of the div you want
document.getElementById('myDivContainer').appendChild(span);

Upvotes: 1

Related Questions