views:

34

answers:

2

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/

+2  A: 

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>
Dean Harding
I guess I could, but the Diff engine I'm using is not language-aware. It only compares strings by a given single-character delimiter. I suppose I could parse my xhtml and add a class if the inner text contains the control character... I have no idea where to start with that though! :)
Iain Fraser
+3  A: 

You can use HTML comments and this plugin (or this one).

SLaks
Nice! I'll definately have a look at this and get back to you!
Iain Fraser
This is probably a better idea, though it would still be a problem if your difference engine works on a character-by-character basis, with no knowledge of HTML (for example, what would happen if someone adds a new attribute to a tag?)
Dean Harding