1
I used to use Buttons inside TD when creating dynamic tables in which each row (TR) has a button.
But I started to see that instead of putting buttons inside the TD, they put a TAG "a" and assigned classes (bootstrap) of buttons to these TAG "a".
Like:
<a class="btn btn-primary">
This already turns a "a" TAG into a button.
Now I’d like to know if instead of me doing this below:
$.each($.parseJSON(data), function(chave, emp) {
//CRIANDO AS LINHAS COM OS TD DA TABELA QUE SÃO O RESULTADO NA CONSULTA AO BANCO
empresas += '<tr id="' + emp.codigo + '">';
empresas += '<td>' + emp.imagem + '</td>';
empresas += '<td>' + emp.usuario + '</td>';
empresas += '<td>' + emp.EMPRESA_ORIGEM + '</td>';
empresas += '<td>' + emp.departamento + '</td>';
empresas += '<td style="text-align: center;"><a class="btn btn-md btn-success" href="#" data-toggle="modal" data-target="#modal-alterar-empresas">ALTERAR</a></td>';
empresas += '</tr>';
});
I might be able to do that.
$.each($.parseJSON(data), function(chave, emp) {
//CRIANDO AS LINHAS COM OS TD DA TABELA QUE SÃO O RESULTADO NA CONSULTA AO BANCO
empresas += '<tr id="' + emp.codigo + '">';
empresas += '<td>' + emp.imagem + '</td>';
empresas += '<td>' + emp.usuario + '</td>';
empresas += '<td>' + emp.EMPRESA_ORIGEM + '</td>';
empresas += '<td>' + emp.departamento + '</td>';
empresas += '<td href="#" data-toggle="modal" data-target="#modal-alterar-empresas" class="btn btn-md btn-success" style="text-align: center;"></td>';
empresas += '</tr>';
});
That would work ?
These questions of assigning classes of buttons in TAGS that are not buttons is a valid thing ?
I’m asking this because I’m having trouble getting a button to occupy all the height and width of a td, and so its background occupies all the td. I even managed to get close, but I can’t do it perfectly and on smaller devices, like smartphones, it looks terrible.
– Gato de Schrödinger
When we work with dynamic elements, what we least want is to use many child elements for a parent. Because, I think, it’s not easy to manipulate them later. That’s why I don’t like to put a "tr" that has a "td" in it and that has a "button" in it and an "a" in the end. That is, 4 elements where maybe we could use only one (the "td").
– Gato de Schrödinger
@Thiagopetherson "like" or "be that easy" is not an excuse to do wrong... In case you have to understand the purpose of the element, normally you will not have an A inside the Btn, you have to see which fits best for what you want to do, and even though I do not like the least problematic eh the A with the button inside, and not the other way around, but for me it’s just... But let’s see sometimes someone comes up with another solution, and btn vc can put with width of 100% to occupy all td
– hugocsl
The 100% width issue doesn’t work completely. And it gets even worse when we use it on devices smaller than 768 px. I tried to use the w-100 and the h-100 of the bootstrap but it still wasn’t 100%. But I agree with you that these gambits are not beneficial in relation to "good practices".
– Gato de Schrödinger