Wh1T3h4Ck5
Wh1T3h4Ck5

Reputation: 8509

string.match() evaluates to null in IE 8 only

I have some working JavaScript code which runs perfectly in other browsers but don't work with IE 8. It's actually simple piece of code and I really can't figure out what's the problem?

In short, while part never gets executed in IE (d.match(pattern) is always null), in all other browsers I'm getting correct offset.

var ids = new Array(),
    d = o.innerHTML,                  // gets correct HTML code in all browsers
    pattern = /id="subblock_(\d+)"/,
    p;

while (d.match(pattern) != null) {

  // IE never gets here!
  p = d.search(pattern);
  ids[ids.length] = d.match(pattern)[1];
  d = d.substr (p+14);

  }

Value of d variable looks like this

<div id="subblock_0">...</div>
<div id="subblock_7">...</div>
<div id="subblock_59">...</div>

Not sure, it looks quite correct to me but obviously Microsoft again doesn't agree with me.

Note: I have tried with IE 8 and last updates of Firefox, Chrome and Opera!

Upvotes: 1

Views: 283

Answers (1)

epascarello
epascarello

Reputation: 207511

I am too lazy to start up a VM, but if I remember right IE8 does not return quotes. A simple console.log(d) would verify that.

pattern = /id="?subblock_(\d+)"?/,

Upvotes: 2

Related Questions