Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
196
rated 0 times [  199] [ 3]  / answers: 1 / hits: 17591  / 15 Years ago, tue, february 9, 2010, 12:00:00

Is there anyway to create a string and add to the DOM? And having Javascript to understand the elements in the string?



I tried the below and 4th line gives error:
var bmdiv = document.createElement('div');
bmdiv.setAttribute('id', 'myDiv');
var str = <b>aa</b>;
bmdiv.innerHTML(str);


I need to add several tags in str to the DIV myDiv



I need NOT to use jQuery since the script will not load jQuery
Thanks.


More From » html

 Answers
29

The innerHTML property is not a function, you should assign it like this:



var bmdiv = document.createElement('div');
bmdiv.setAttribute('id', 'myDiv');
var str = <b>aa</b>;
bmdiv.innerHTML = str;

[#97624] Friday, February 5, 2010, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
andrewb

Total Points: 259
Total Questions: 124
Total Answers: 90

Location: Ivory Coast
Member since Sun, Mar 7, 2021
3 Years ago
;