Reputation: 1
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
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