1
In the example below, is displayed the multiplication of the value of the "checkbox" (if checked) by the value chosen in the "select" of the same line, there is a "reset" of the respective "select" when unchecking the "checkbox" and there is a result in parallel only the sum of the values of the select.
This code is the result of previous questions (lessons) here from Stack, with the tips I managed to make it work perfectly.
My beginner question is, is there redundancy in the code in this way that I did and is it possible to do everything with a single each()? As you can see, there are two "each()":
$('tr').each(function(){ _código_ });
and $('table input').each(function(){ _código_ });
.
Following functional example for better understanding: https://jsfiddle.net/8uk440do/18/
From now on, thank you for helping me learn.
Just warning, we missed one
)
ai in the question code.– user28595
Thanks @Diegof, I made the corrections.
– Danilo Fagundes
Danilo, one parenthesis is still missing:
$('tr').each(function())
and$('table input').each(function(i))
– user28595
Thanks @Diegof, I made the corrections...
– Danilo Fagundes
Danilo, the
each()
serves to interact a collection running a particular code snippet, in your example, both collections are different and the executed code is also different... so the code does not have redundancy... you could even do it with a singleeach()
, but the code would be dirty and make it difficult to understand it.– Tobias Mesquita
Got it @Tobymosque, thank you. In your opinion, didactically speaking, this is the best way to do this?
– Danilo Fagundes
Yes, I believe it is.
– Tobias Mesquita
@Tobymosque, thank you
– Danilo Fagundes
@Tobymosque, good morning. Basically what changes for the use of each() methodology in a structure of "Divs", without table structure, tr... ? I am here trying to apply the last learning that you have passed me
– Danilo Fagundes