Jquery Sorting by Letter
- by Batfan
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.