Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use DIV or TABLE?

Tags:

html

css

tabular

I need to build a simple table of data. So usually I would just say let's use tables, that's what they are for.

However there is and extra little trick here which is if you click "show" there is an ajax call to show extra data below. Which makes me wonder, should I switch to DIVs?

I know both are possible - but I'm trying to see what is cleaner and easier...

data is fake (data here is fake)

like image 744
Nathan H Avatar asked Mar 18 '26 10:03

Nathan H


2 Answers

You answer your own question - the data is tabular, with horizontal and vertical relationships, so the semantically correct markup is most definitely a table. The intended user interface should never factor in semantics choices.

You can easily, and correctly, implement the show button by inserting a new tr element underneath the clicked one with the correct data.

Considering the original markup is as follows:

<tr>
    <td>1</td>
    <td>Orlando</td>
    <td>Gee</td>
    <td>phone number</td>
    <td><button>show</button></td>
</tr>

You can then, in JS, append the required new rows, one per attribute:

<tr class="otherbg-and-bold">
    <td></td>
    <td colspan="2">email address</td>
    <td colspan="2">[email protected]</td>
</tr>
like image 173
Niels Keurentjes Avatar answered Mar 21 '26 01:03

Niels Keurentjes


<table> tags are for tabular data. And tabular data is what you have there. So go ahead, using tables should be just fine.

like image 28
Dennis Traub Avatar answered Mar 21 '26 01:03

Dennis Traub



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!