Can I place a TD of a TABLE with button features through Bootstrap classes?

Asked

Viewed 199 times

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 ?

1 answer

1


Dude are a lot of details, but I’m telling you right away that this is completely wrong, because you can’t put a href in a TD, and that would have no semantics or even be accessible

<td href="#" data-toggle="modal" data-target="#modal-alterar-empresas" class="btn btn-md btn-success" style="text-align: center;"></td>

The option to customize a tab <a> as a <button> doesn’t make much sense, except for the fact that button you can’t put a link href, because it is used to submit or for an action via JS. In addition, the button can make a submit and be accessed with the key Backspace (space) for example, and has a different semantics than an A that is actually a hyperlink.

You can even customize one <a> as a <buttom>, but their purpose is quite different as well as the semantics already said above.

As you can see here the global attributes of a button are totally different from the A https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button

The HTML Element represents a clickable button.

Element A https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a

The HTML element (or the HTML Anchor Element defines a hyperlink (hyperlink), the destination of a hyperlink, or both.

  • 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.

  • 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").

  • @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

  • 1

    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".

Browser other questions tagged

You are not signed in. Login or sign up in order to post.