O'Reilly logo

Learning jQuery Third Edition by Karl Swedberg, Jonathan Chaffer

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using HTML5 custom data attributes

So far, we've been relying on the content within the table cells to determine the sort order. While we've managed to sort the rows correctly by manipulating that content, we can make our code more efficient by outputting more HTML from the server in the form of HTML5 data-* attributes. The second table in our example page includes the following attributes:

<h3>Table 2</h3> <table id="t-2" class="sortable"> <thead> <tr> <th></th> <th data-sort='{"key":"title"}'>Title</th> <th data-sort='{"key":"authors"}'>Author(s)</th> <th data-sort='{"key":"publishedYM"}'>Publish Date</th> <th data-sort='{"key":"price"}'>Price</th> </tr> </thead> <tbody> <tr data-book='{"img":"2862_OS.jpg","title":"DRUPAL 7","authors":"MERCER ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required