leora
leora

Reputation: 196881

Why doesn't this javascript string code work in internet explorer 7?

I have the following code that works fine in IE8, firefox, chrome but not in IE7

Can someone please explain why this code below doesn't work in IE7 ?

  var myString = $(this).attr("id");
  var nextStep = myString [myString.length - 1];

basically, IE7 doesn't seem to understand this line:

   myString [myString.length - 1]

In this case myString is just a regular string that i am parsing out from the id of a div.

Upvotes: 2

Views: 92

Answers (1)

Matt Greer
Matt Greer

Reputation: 62057

IE7 does not recognize indexing a string in that way. You need to use myString.charAt(myString.length - 1).

Array-like indexing of a string was added to ECMAScript 5, which was released well after IE7 was. More info

Upvotes: 4

Related Questions