How to allow special characters in jQuery “contains”?

How to allow special characters in jQuery “contains”?

Original question asked  here .

So when this function is triggered it selects an item in a list via filtering elements with that class and with the text that the user provides through the var text. 

If the above exists then it simply clicks that element, else show an error. 

However if the user provides text like "hi(hello world)", this would be seen by jQuery as part of the function and not text, so it doesn't work. 

So any special characters like "!/-()" will be seen as part of the function and not text. 

This has really bugged me. The only solution I can see is to store the parameters in an hidden field and call it that way.  Appreciate any replies!


  1. function selectListItems(Parameters) {

  2.     var text = Parameters[1];

  3.     var tdtext = $(".childNode").filter(function () {
  4.         return $.text([this]) == Parameters;
  5.     });

  6.     if (tdtext && tdtext.length > 0) {
  7.         tdtext.click();
  8.     } else {
  9.         alert("Error Coming")
  10.         showErrorConfirmBox();
  11.     }
  12. }