jquery - Hide All But First Matching Element -
I am using jquery to sort through several paragraphs. Currently I have to show it only paragraph which starts with the current letter. But now, I would like to strengthen further. If there are many instances in the text between the paragraph tags, then I would like all of the hidden first.
It is so close to me, but it is not working.
Var characters = '& lt ;? Php echo (strlen ($ _ GET ['letter']) == 1)? $ _GET ['Letter']: ''; ? & Gt; 'Function Finish () {jQuery (' P '). Each (function () {if (jQuery (this) .text (). Substr (0,1) .toUpperCase () == letter} {jQuery (this) .addClass ('current-series'); jQuery (this) HTML (letter + '& lt; span class = "hidden" & gt;' + jQuery (this) .text (). Piece (1) + '& lt; / span & gt;');} Other {jQuery (This) .hide ();}}}}
Update:
Sorry, it's hard to know that this link Here's a basic example:
- The selected letter B
- The returned values are:
the ball
< P> BallBall
Brain
Bats
Bats
In each of these Paragraph tags of
boy
brain
bat
It will hide everything, but the first paragraph with the first letter:
Edit: You can solve the following messy.
function (Finnish) {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;} and {jQuery (this) .hide ();}} else {JQuery (this) .hide ();}}}}
Comments
Post a Comment