<p>It seems pretty common to want to let your javascript know a particular dom node corresponds to a record in the database.  So, how do you do it?</p>

<p>One way I've seen that's pretty common is to use a class for the type and an id for the id:</p>

<pre><code>&lt;div class="thing" id="5"&gt;
&lt;script&gt; myThing = select(".thing#5") &lt;/script&gt;
</code></pre>

<p>There's a slight html standards issue with this though -- if you have more than one type of record on the page, you may end up duplicating IDs.  But that doesn't do anything bad, does it?</p>

<p>An alternative is to use data attributes:</p>

<pre><code>&lt;div data-thing-id="5"&gt;
&lt;script&gt; myThing = select("[data-thing-id=5]") &lt;/script&gt;
</code></pre>

<p>This gets around the duplicate IDs problem, but it does mean you have to deal with attributes instead of IDs, which is sometimes more difficult.  What do you guys think?</p>

```
```
<div class="thing" id="myapp-thing-5"/>

// Get thing on the page for a particular ID
var myThing = select("#myapp-thing-5");

// Get ID for the first thing on the page
var thing_id = /myapp-thing-(\d+)/.exec ($('.thing')[0].id)[1];
```
```