Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to put pre-existing text in an ordered list?

I have some pre-existing recipe ingredients that I want to put into an order list in the HTML file. Like the list below, is there a way to put each ingredient into the list without manually copy and pasting it one by one? I am currently trying to use emmet abbreviations and so far I tried ol>li*13> ["paste in the ingredients"] it does not work.

e.g.

Sticky Garlic Shrimp

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

salt
pepper
sesame seeds
lemon slices
cooked brown rice (to serve)
1 tablespoon reduced-sodium soy sauce
1 teaspoon fresh ginger, minced
1 tablespoon olive oil
1 spring onion
1/4 teaspoon crushed chili flakes (optional)
3 cloves of garlic, minced
3 tablespoons honey
1400g uncooked shrimp, peeled & deveined

and I want it in the following:

  1. salt
  2. pepper
  3. sesame seeds
  4. etc

>Solution :

Yes, you can do it by looping through your array in JavaScript, and appending them one by one:

Create an HTML element for your list:

<div id="food_div"></div>

JavaScript at the bottom of the HTML file:

var food_items = ["salt", "pepper""]
var str = '<ul>'

food_items.forEach(function(el) {
   str += '<li>'+ el + '</li>';
}); 

str += '</ul>';
document.getElementById("food_div").innerHTML = str;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading