3

i am trying to place array into innerHTML but add a newline after each element,

var ingr_list = [];

//then i push some items

if (checkBox.checked == true){
    text.style.display = "none"; 
    ingr_list.push(nameofingredient);
    document.getElementById('ingredienttype').innerHTML = ingr_list;

As for now it just show array as entire line which ruins my responsiveness (the longer the array gets the wider screen grow which i do not know how to fix - \n or would do the trick)

1 Answer 1

3

Join the array elements with <br> tags like this:

var output = ingr_list.join('<br>');
document.getElementById('ingredienttype').innerHTML = output;
Sign up to request clarification or add additional context in comments.

1 Comment

@jdow - You are very welcome! Please accept my answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.