Answer the question
In order to leave comments, you need to log in
What is the best approach?
There is data in json format. JS parses and creates elements on the page based on them.
For each object in json, there are several elements on the page and they are connected:
an element card, an element in the menu, a checkbox. label, icon.
When clicking on each, some action should take place with another related element (for example, when clicking on a checkbox, hide the card, and when clicking on a card, highlight the menu item).
Actually the question is which of these 2 ways to choose and what will be more optimal / correct:
1. Create an array in which to write objects for each element, for example:
var items = [];
...
var current_elem = {};
current_elem.menuDiv = createDiv();
current_elem.iconDiv = createDiv();
current_elem.cardDiv = createDiv();
current_elem.checkboxDiv = createDiv();
current_elem.labelDiv = createDiv();
items.push(current_elem);
...
hide(document.getElementById('checkbox-for-' + this.getAttribute('data-element-id')));
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question