javascript - Store info i element, a good practice? -
Say I have a list of movies where I can replace the title, rating and cost of films with JavaScript and Jquery via HTML Control. . The original values of these variables will be given when the page will load. So far, I load the data in elements like this:
and lt; Div class = "movie0" data-rating = "320" data-name = "movie-name number1" data-cost = "26> ; / Div> & lt; div class = "movie1" data-rating = "110" data-name = "movie-name number 2" data-cost = "18" & lt; img src = "Movie2.png" /> & lt; / div & gt; & lt; div class = "movie 2" data-rating = "315" data-name = "movie-name number 3" data-cost = " 25 "& gt; & lt; img src =" movie3.png "/> & lt; / div>
HTML control, jQuery .data () function Change the data using.
For the question now. It would be better to load the information into a JSON object and then the ID (or a data attribute) is related to an index in the JSON object. Instead of changing the elements, they will replace the index in the JSON object related to the element. What's better? If I only have the rating variable for priority?
EDIT: I am asking this question because I have read and heard that the DOM stores And changing information is disabled.