1

I am looking for a more intuitive way to run the code below (as it is also incomplete to my purpose).

for (j = 0; j<items.length; j++) {
            var indivItem = items[j];
               if (indivItem.category == 1) {
                  $('.indiv_category[idnumber="1"]').append('<ul class="left_side_item"><li>'+indivItem.title+'</li></ul>');
               }
               else if (indivItem.category == 2) {
                  $('.indiv_category[idnumber="2"]').append('<ul class="left_side_item"><li>'+indivItem.title+'</li></ul>');
               }
            }

Essentially I need line 3 to check if (indivItem.category > 0) then look for the element with a matching idnumber attribute and append the necessary info.

I need this continue for the length of available .indiv_category elements.

Basically a matchup of the all items in the 'items' array to all of the elements with a matching 'idnumber' attribute to the item in the array that contains the same id number.

0

1 Answer 1

3

Remmove the condition and just use the variable items[j].category in selector.

for (j = 0; j<items.length; j++) {             
    $('.indiv_category[idnumber="'+ items[j].category + '"]').append('<ul class="left_side_item"><li>'+indivItem.title+'</li></ul>');             
}
Sign up to request clarification or add additional context in comments.

Comments

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.