1

Anyone help with this jQuery I'm trying to pull off I can't get the regex to work

cj("input[id='PRE_TEXT_'(.*)'_POST_TEXT']").hide();
1
  • 2
    This isn't how jQuery selectors work. You'll need to use $.filter() and use your regex in the function you pass to it. Commented Apr 18, 2012 at 14:13

2 Answers 2

3

You can't use regex in jQuery selectors. Use the filter function:

cj("input").filter(function() {
    if (/^PRE_TEXT_(.*)_POST_TEXT$/.test(cj(this).prop("id"))) {
        return true;
    }
    return false;
}).hide();
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Micha James solution below has done the trick, but this will help in future.
@Generic yes James solution is better, I just left this post for future visitors who really are in need to use a complex regex.
2

You can't use regex, but you should be able to use startswith and endswith.

cj("input[id^='PRE_TEXT_'][id$='_POST_TEXT']").hide();

1 Comment

Thanks James works perfect I should have thought of this bit new to regex.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.