1
I have the following structure in my HTML:
<!-- O número de tbody's sera gerado dinamicamente, de acordo com o número de estados -->
<tbody name="tbodyEstados">
<tr style="background:#F5F5F5;">
<td>
Nome do estado
</td>
</tr>
<tr>
<td>
<!-- o número de div's será gerado dinamicamente -->
<div name="divOficina">
<label>
Nome de uma oficina
<input type="hidden" value="id_do_objeto">
</label>
</div>
</td>
</tr>
</tbody>
Through javascript, I’m using the Document.getElementsByName('tbodyEstados') function to get an array of all tbody’s of states, but then I need to iterate each of the items in that list and take them from within, separately for each state, the div elements that are with the name: "divOficina". Does anyone know how I can do it?
The element
tbody
should not repeat itself several times in the same table. Revise your logic. You could take directly the DivsdivOficina
withdocument.getElementsByName('divOficina')
– Roberto Braga
The problem with directly using Document.getElementsByName('divOficina') is that I won’t know which of these divs are within which state specifically.
– Ian Ramos
Add a status attribute when typing div. Ex.:
<div name=divOficina estado=DF>...</div>
. When making a loop on Divs, you check the attribute like this:minhaDivOficina.getAttribute('estado')
.– Roberto Braga
It is recommended that custom attributes be prefixed by
data-
to avoid incompatibilities https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Using_data_attributes, https://answall.com/questions/190859/attributespersonalizated-html– edson alves