Jquery Sorting by Letter
Posted
by Batfan
on Stack Overflow
See other posts from Stack Overflow
or by Batfan
Published on 2010-06-15T22:37:14Z
Indexed on
2010/06/15
22:42 UTC
Read the original article
Hit count: 252
I am using jquery to sort through a group of paragraph tags (kudos to Aaron Harun). It pulls the value "letter" (a letter) from the url string and displays only paragraphs that start with that letter. It hides all others and also consolidates the list so that there are no duplicates showing.
See the code:
var letter = '<?php echo(strlen($_GET['letter']) == 1) ? $_GET['letter'] : ''; ?>'
function finish(){
var found_first = [];
jQuery('p').each(function(){
if(jQuery(this).text().substr(0,1).toUpperCase() == letter){
if(found_first[jQuery(this).text()] != true){
jQuery(this).addClass('current-series');
found_first[jQuery(this).text()] = true;
}else{
jQuery(this).hide();
}
}
else{ jQuery(this).hide();}
})
}
Been working with this all day and I have 2 Questions on this:
Is there a way to get it to ignore the word 'The', if it's first? For example, if a paragraph starts with 'The Amazing', I would like it to show up on the 'A' page, not the 'T' page, like it currently is.
Is there a way to have a single page for (all) numbers? For example, the url to the page would be something similar to domain.com/index.php?letter=0 and this would show only the paragraph tags that start with a number, any number. I can currently do this with single numbers but, I would like 1 page for all numbers.
© Stack Overflow or respective owner