1

I'm having troubles with getting this code to be case-insensitive. This code is found online - (http://jsfiddle.net/bizamajig/radzq2o2/)

 $(function(){ // Instantiate MixItUp: $container = $('.cd-gallery') $container.mixItUp(); $('#filter').keyup(function(){ var val = $(this).val(); var state = $container.mixItUp('getState'); var $filtered = state.$targets.filter(function(index, element){ return $(this).text().toString().indexOf( val.trim() ) >= 0; }); $container.mixItUp('filter', $filtered); }); }); 

But I can't seem to get this code to be case-insensitive. I've tried different things - but nothing worked. Can anyone help me?

I need this code (above) to be case-insensitive.

Thank you!

1
  • have you tried using regex ? Commented Jun 29, 2017 at 8:10

2 Answers 2

2

Just change

return $(this).text().toString().indexOf( val.trim() ) >= 0; 

to

return $(this).text().toString().toLowerCase().indexOf( val.trim().toLowerCase() ) >= 0; 

Notice the use of toLowerCase(). We basically convert both the strings being compared to lower case letters before comparing them.

A fork of your fiddle, with the suggested change: http://jsfiddle.net/kykuwppL/

Sign up to request clarification or add additional context in comments.

2 Comments

Omg - thank you so much! I did try the .toLowerCase where you put it the first time - but didn't add it the second time at the end! Doh. ! THANK YOU!
You're welcome. If this solved your problem, please consider accepting the solution. :)
0

convert both strings .toLowerCase(): var val = $(this).val().toLowerCase(); return $(this).text().toString().toLowerCase().indexOf(val.trim()) >= 0;

$(function(){ // Instantiate MixItUp: $container = $('#projects') $container.mixItUp(); $('#filter').keyup(function(){ var val = $(this).val().toLowerCase(); var state = $container.mixItUp('getState'); var $filtered = state.$targets.filter(function(index, element){ return $(this).text().toString().toLowerCase().indexOf( val.trim() ) >= 0; }); $container.mixItUp('filter', $filtered); }); }); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.