+ 1
I want to do list item with ordered list. I do this. I have error and i haven't output. Thanks you.
Ordered list item. https://code.sololearn.com/W5mLJ6XQOBxU/?ref=app
7 Answers
+ 1
Errors were quite self explanatory ,so it would be better to understand how dom works and how objects hold a property or a function and what they don't hold(like you could have looped over object to see why you are getting error) to avoid confusion in future.
Maybe you needed this ?
var myol = document.getElementById ("parent");
var li= document.createElement ("li");
myol.appendChild(li);
li.innerHTML="Glucose";
document.body.appendChild (myol );
0
And i do it. It is one child of parent. How Can i do more child. Thanks you.
0
is it list item ?
0
Malick Diagne li is a ordered list (ol) item.
To create more child list for the ordered list , use document.createElement for every new element .
For example
array=["something","something"]
for(let i=0;i<2; i++){
var li=document.createElement("li");
li.innerHTML=array[i];
ol.appendChild(li);
}
0
How about with HTML only?
<body>
<ol>
<li>Glucose</li>
<li>pommade</li>
<li>bande de crĂȘpe</li>
</ol>
</body>
0
Use the document.createTextNode("glucose")
Istead of innerHTMl
Then append it to the li items