0

I've got a fairly simple loop that supposed to run through all elements in the document and stick the ones with a class containing "toggler" in an array. Here's a JSFiddle with an example

As you can see, there are obviously 3 togglers defined but the loop is only counting two. It seems to be skipping any element directly following a positive match, but I can't figure out why. Any ideas?

1
  • unfortunately no, this is being used in an extremely outdated and restrictive environment (IE 6 even!) Commented Jun 13, 2012 at 19:09

1 Answer 1

1

Drop the g example:

  var togglerTest = /toggler/;

As with exec (or in combination with it), test called multiple times on the same global regular expression instance will advance past the previous match.

meaning it will match every other toggler due to the g.

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

1 Comment

D'oh.. that did the trick, although I'm not 100% sure why. I'm fairly new with regular expressions

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.