-1

I am using jQuery 1.7.1. I need to make a filter(':contains("XXX")') selector case insensitive. I have tried this and this with no luck means it is not working. To be precise, $('div:contains') works but filter(':contain') does not

Community
  • 1
  • 1
Imran Qadir Baksh - Baloch
  • 32,612
  • 68
  • 179
  • 322
  • 1
    How come the listed solutions didn't work? They **should**. – VisioN Feb 12 '13 at 12:00
  • In fact, I didn't check the linked questions but you really should precise what's your problem with the answers, as suggered by @VisioN. Or this question might be closed. – Denys Séguret Feb 12 '13 at 12:02
  • Please be more specific, do you need 1) the selector to be case sensitive, or 2) the text of a known selector element to be case sensitive ? – Arindam Feb 12 '13 at 12:04
  • @VisioN, Very bad that you did'nt read the question thoroughly. The link discussing :contains and I am using filter(":contains").Test it your self. – Imran Qadir Baksh - Baloch Feb 12 '13 at 14:07

1 Answers1

6

Use a regular expression and the filter function :

yourJquerySet.filter(function(){ return $(this).text().match(/XXX/i) })

If your string XXX is dynamically provided, use

var r = new RegExp(str, 'i'); 
var outputset = inputset.filter(function(){ return $(this).text().match(r) })
Denys Séguret
  • 372,613
  • 87
  • 782
  • 758