18.04.2016 Views

Professional JavaScript For Web Developers

javascript for learners.

javascript for learners.

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 12<br />

The concept<br />

Keep in mind is that each cell in a table must have a sortable value, meaning a value that is a string, integer,<br />

float, or date. Because all HTML code can’t be converted directly into one of these data types, you<br />

need to specify an alternate value to sort by. This can be accomplished by adding an extra attribute on<br />

each that contains HTML, like this:<br />

<br />

Because this table cell contains an image, you normally wouldn’t be able to sort it. However, the addition<br />

of the value attribute specifies that the value to sort is “blue”, not the contents of the element.<br />

And as you learned earlier, it is possible to access this new attribute using the DOM getAttribute()<br />

method:<br />

var sValue = oTD.getAttribute(“value”);<br />

Now, it isn’t necessary to add a value attribute to every cell in a table, because this gives you a lot of<br />

redundant information. You should only add the attribute to those table cells containing HTML code.<br />

<strong>For</strong> example, the following table lists filenames along with their associated icons. Note that only the first<br />

column uses the extra value attribute:<br />

<br />

<br />

<br />

Type<br />

Filename<br />

<br />

<br />

<br />

<br />

<br />

My Resume.doc<br />

<br />

<br />

<br />

Fall Budget.xls<br />

<br />

<br />

<br />

How to be a better programmer.pdf<br />

<br />

<br />

<br />

My Old Resume.doc<br />

<br />

<br />

<br />

Notes from Meeting.txt<br />

<br />

<br />

<br />

Backups.zip<br />

382

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!