0

I am trying to setup a filter in isotope that will filter by only the first letter of text in an tag. Any help is appreciated! (new to javascript!)

Lee Taylor
  • 7,761
  • 16
  • 33
  • 49

1 Answers1

0

Can you use regular expressions?

$('#container').isotope({ filter: '^[^\*]' });

•The first ^ means "at the start of the string" The [ ... ] construct is a character class, which matches a single character among the ones enclosed within the brackets

•The ^ in the beginning of the character class means "negate the character class", i.e. match any character that's not one of the ones listed

•The * means a literal *; * has a special meaning in regular expressions, so I've escaped it with a backslash.

Src= Javascript regexp - only if first character is not an asterisk

Community
  • 1
  • 1
dev
  • 3,969
  • 3
  • 24
  • 36
  • I believe I can use expressions, yes. So, if I wanted to turn that into a click function, i.e. when a link for "A" (A) is clicked it will filter all titles within

    tag that begin with "A", how would I write out that out?

    – user1883431 Dec 07 '12 at 01:25
  • It will be something like this, but will probably need tweaking. `$('#IDofyourbutton a').click(function(){ $('#container').isotope({ filter: '^[^\A]' }); });` – dev Dec 07 '12 at 12:35