Getting data for a web app from the dom

Just curious is it bad practice to take data from the dom and parse it into an integer and do work on that as opposed to using dom to represent your JavaScript? This is my pomodoro clock and basically my application logic was based off of parse inting values that were represented in the DOM and doing work on that.

Don’t see why not since it’s a simple application that parses an int.
One thing though that I think it would help you is to check in the code that you are actually getting an int.

For a simple application, I guess it wouldn’t matter much.

But for other complex apps with lots of interaction, and where updates to one data value may affect multiple parts/views of the DOM or the operation of the program, then this can become difficult to keep track of which “view” areas you need to update. Another situation may be the “view” needs to display “5 minutes”, for example. Are you going to get that string “5 minutes” from the DOM and parse it to get rid of " minutes" then convert that string to int. You see what I’m saying?

Best practice is you update the “model”, i.e. the data/variables behind the scenes and you work using that value. The “view” on the browser page will be updated automatically as the values/content of your “model” variables changes under program control (i.e. by your controller). That way, it doesn’t matter if there are several elements on your view/page that is dependent on that single model value, all of them will be updated automatically.

I actually just reworked the code so that the DOM represents values of variables instead of taking values from DOM. I feel like my code is more readable now due to the fact. I appreciate your words of wisdom, owel, It’s nice to learn about the reasoning behind doing certain things.