Hide All But First Matching Element
- by Batfan
I am using jquery to sort through multiple paragraphs. Currently I have it set to show only paragraphs that start with a current letter. But now, I would like to consolidate further. If the text between the paragraph tags has multiple instances, I would like all but the first hidden.
This is what I have so far but, it is not working.
var letter = '<?php echo(strlen($_GET['letter']) == 1) ? $_GET['letter'] : ''; ?>'
function finish(){
jQuery('p').each(function(){
if(jQuery(this).text().substr(0,1).toUpperCase() == letter){
jQuery(this).addClass('current-series');
jQuery(this).html(letter + '<span class="hidden">'+jQuery(this).text().slice(1)+ '</span>');
}
else{ jQuery(this).hide();}
})
}
Update:
Sorry guys, I know this is kind of hard to explain. Here's a basic example:
The selected letter is B
The values returned are:
Ball
Ball
Ball
Boy
Brain
Bat
Bat
Each of these values is in a paragraph tag.
Is there a way to consolidate to this?
Ball
Boy
Brain
Bat