开发者

How do you sort paragraph tags, or TD tags (for example), alphabetically?

Say there is a table; I want to get the values in the third column of that table and alphabetize them. I couldn't figure out how to pull information from html tags and alphabetize the text within, because I think it was alphabetizing the elements (all of which were the same).

Anyway, here's an example of my problem. As you can see, I can get an alphabetized list from using alert(), but not with document.write() or jQuery's append(). Also notice that I can write a specific element from the array.

Why is this, and how can I resolve this issue?

Here's 开发者_开发知识库the code: http://jsfiddle.net/bozdoz/kd4R7/


Just use .toString like this:

$('.here').append(letters.toString());

in your code and it works. letters is an array and it needs to be converted to string before append can be done. Or in a better way, use html instead of append like this:

$('.here').html(letters.toString());

This will replace the contents of .here instead of appending.


It might not be what you're asking for but for table sorting http://tablesorter.com/docs/ is really nice.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜