I would like to have an entire table row clickable, without using javascript. The Internets tell me this isn't possible with HTML4, but I'm using HTML5, so I'm hopeful.
However, the obvious doesn't work:
<table>
<a href="foo">
<tr>
<td>…</td>
<td>…</td>
</tr>
</a>
</table>
Firebug reveals that Firefox pulls the <tr/> element out of the <a/> wrapper when computing the element tree, and puts an empty <a/> before the <table/> like this:
<table>
…
</table>
This looks to me like what I'm trying is either not allowed by the standard, or there's a bug in Firefox (and Chromium, which showed the same behaviour). I'm guessing the former, and indeed, the HTML5 specification tells us that <td/> can't be used within an <a/> element, but only within other table-elements: The tr element.
Any other hints on how I could achieve clickable table rows using HTML5?
Apparently, this hasn’t changed in HTML5, so we’re still left with the mentioned workarounds.
You can have the clickable row span the number of columns you need and put the content I that one row
<table>
<tr>
<td>col 1</td>
<td>col 2</td>
</tr>
<tr >
<td colspan="2">
<a href="foo">
Clickable stuff. If you need table columns here, you can nest a second table here
</a>
</td>
</tr>
</table>
what is wrong with the following?
<table>
<tr> <th> Blah </th> <th colspan="2"> Something </th> </tr>
<tr> <td> .. </td> <td colspan="2"> ... </td> </tr>
</table>
It says Table column 3established by element th has no cells beginning in it.
As the error message says, there is no cell that begins in the third column. It thus violates the HTML table model as defined in HTML5, rather technically in 4.9.12 Processing model. Basically, the point is that you cannot create a column that consists only of slots created by cells starting in earlier columns and extending to other columns with colspan.
When using earlier versions of HTML, the error won’t be caught, since for them, validation is DTD-driven, and a DTD (document type definition, a formalized set of syntax rules written in SGML or XML) can only describe relatively simple syntax rules.
The most common cause of this problem seems to be a misguided idea of just making cells wider by using colspan. Instead, use the width attribute or, usually more preferably, the width property in CSS.
I've validated your HTML code with two doctypes:
HTML5;
XHTML 1.0 Strict.
And your document was successfully checked as valid.
You should try to revalidate it.
<table>
<td>cell1</td>
<td>cell2</td>
</table>
I found out that this tags work on ie8, firefox 11 and chrome, but not sure whether this is valid by standards and work on all major browsers.
All browsers accept "quirks" in HTML layout and will render a "best guess" based on what they find. But in the HTML specifications, a <tr> tag is DEFINITELY required — regardless of whether it works or not, you should always use valid HTML!
Check early, check often!
http://validator.w3.org/
<tr> tag is of course required with <table>, it specifies the begining and ending of the particular row, so it can't be neglected.
According to w3c </TD> and </TR> tags are optional, so the following table is perfectly valid.
<table>
<tr>
<td>google
<td>chrome
</table>
And all browsers I've tested it with render the table fine. I just wanted to ask if this is generally considered safe to use, or if older browsers, which I don't have access to, cause problems. Thanks.
It reduces gzip html size on a page with many tables by a few percent.
This is valid HTML but invalid XHTML.
There's nothing intrinsically wrong with it.
If you look at the source for Google's privacy policy (or any of their other pages), you'll find some much terser HTML.
It does mean that your page will not be usable by an XML parser.
It is safe, since optionality in the standard means that all the browsers (at least the ones which even remotely matter) would have implemented this - and the browser standards compliance usually runs to the opposite side, into trying to work correctly with even invalid HTML as opposed to failing on missing optional tags.
Having said that, I find that omitting such tags makes things harder to read, which may or may not matter to you if the goal is size optimization.
P.S. Also, if you have very large tables, I wonder whether there's any overhead incurred by the browser's HTML parser when dealing with such constructs? I am not sure without benchmarking or really deep thinking about how HTML parser works in detail, but it is something that could possibly be a factor if it happens.
I strongly recommend against doing that, though it is valid in HTML4 (and 5). The bandwidth savings are miniscule when compared to the technical debt you are incurring. Also keep in mind it is not valid in XHTML, so be sure your doctype is set appropriately.
There have been optional tags in HTML since the very beginning — they are a feature inherited from SGML, and so the early browsers must have been able to deal with them. While XHTML moved away from this and required a much more uniform syntax, this doesn’t affect you unless you explicitly tell the browser to parse in XML mode. I’ve never seen a problem when using the standard parsers of HTML 4/5.
Since HTML5 so carefully describes when certain tags are optional, I would read that to imply that someone did lots of testing to make sure that in these cases, most browsers produce the same document tree.
And while the space savings are negligible, I find that leaving off the closing tags of <p>, <li>, <td>, and <tr> simply makes my life easier when I’m working in the markup, and makes me less likely to make an error.
Personally I don't consider it good practice. Looking at the spec it didn't give a whole lot of information. I know it's required for XHTML so I looked up the HTML 5 spec. HTML 5 seems to take the same take on it as HTML 4 which is what you've linked to, but gives a little more information:
A td element's end tag may be omitted if the td element is immediately followed by a td or th element, or if there is no more content in the parent element.
I advise always closing your tags. There's not really too good of a reason not to. Browsers can handle some improperly closed tags, but just to be on the safe side (and it's good programming practice!), close your tags!
Close all tags in HTML for a few reasons:
Not closing tags is tolerated, but it is not correct modern XHTML. It's deprecated much in the same way that HTML style attributes are in favor of CSS
It's more readable for the next guy if you close the tags
Browsers will actually have an easier time parsing your source if it more strictly adheres to the rules, even if that makes the source longer
Certainly if you are using only HTML there is absolutly no problem thats not the case with XHTML nevertheless i don't think you can get that much, also i suggest dont abuse tables remember div are better than tables
It’s Ok with Static Pages not for Dynamic Pages …to debug
You should close your <TR> and <TD>tags if possible, but NOT ALWAYS because in some scenarios it may disturb you. This is because the <TR> and <TD>tags could be styled to display:none while the </TR> tag couldn't. It means that a scenario in which you want to extend / limit your display with media queries, will fail if you use </TR>. Consider the following code:
<style>
#media (max-width : 480px) {
.hidden-class {display:none;}
}
</style>
<table>
<tr>
<td>cell 1</td>
</tr class="hidden-class"> <!-- this will fail! -->
<tr class="hidden-class">
<td>cell 2</td>
</tr> <!-- this could stay -->
</table>
It means that you would write it as:
<table>
<tr>
<td>cell 1</td>
</tr> <!-- this will now close the TR for every screen width, which will destroy your extenstion -->
<tr class="hidden-class">
<td>cell 2</td>
</tr> <!-- this could stay -->
</table>
Which means that the only way to do so is by OMITTING THE in the first place:
<table>
<tr>
<td>cell 1</td>
<tr class="hidden-class">
<td>cell 2</td>
</tr> <!-- this could stay -->
</table>
I would like to be able to place an empty tag anywhere in my document as a marker that can be addressed by jQuery. However, it is important that the XHTML still validates.
To give you a bit of background as to what I'm doing: I've compared the current and previous versions of a particular document and I'm placing markers in the html where the differences are. I'm then intending to use jQuery to highlight the parent block-level elements when highlightchanges=true is in the URL's query string.
At the moment I'm using <span> tags but it occurred to me that this sort of thing wouldn't validate:
<table>
<tr>
<td>Old row</td>
</tr>
<span class="diff"></span><tr>
<td>Just added</td>
</tr>
</table>
So is there a tag I can use anywhere? Meta tag maybe?
Thanks for your help!
Iain
Edit: On the advice of codeka, I may look for a better difference engine and I may have found one that is attuned to finding differences in XHTML: http://www.rohland.co.za/index.php/2009/10/31/csharp-html-diff-algorithm/
You can use HTML comments and this plugin (or this one).
Can you not just modify the class of elements that have changed?
<p class="diff other-class">Something changed</p>
<table>
<tr>
<td>Old row</td>
</tr>
<tr class="diff">
<td>Just added</td>
</tr>
</table>