3

As a step to learn jQuery, I am trying to create Sudoku, in which I generated numbers in div blocks from 1 to 89 (leaving 10 divisible numbers). My code works good in Google chrome but IE8 generates the div id's differently.

Please check this fiddle

I highly doubt the error must be because of incompatibility of some methods of jQuery. The problem could be in the following steps:

var lastNumId = parseInt(_idGen.toString().substr(-1), 10);
var secondLastNumId = parseInt(_idGen.toString().charAt(_idGen.length - 2), 10);

In the above lines to do the same, I used different techniques because if I do so then it is working in Chrome.

5
  • 2
    If parseInt seems to be the problem try just using Number(str) or even +str, and see if that does it... Commented Jan 26, 2013 at 8:30
  • None of those are jQuery properties. Commented Jan 26, 2013 at 8:30
  • @elclanrs I used var lastNumId = Number(_idGen.toString().substr(-1));.. still same.. in IE8 Commented Jan 26, 2013 at 8:33
  • @Juhana I changed it to methods. I think it is correct now. Commented Jan 26, 2013 at 8:35
  • Those have nothing to do with jQuery... they're plain JavaScript. Commented Jan 26, 2013 at 9:00

1 Answer 1

4

Using a negative index in substr is not supported by IE until version 9.

Just use the modulo operator to get the last digit of the number. This works in IE8 also:

var lastNumId = _idGen % 10;
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks this is working.. I thought it doesnt convert string to int automatically.

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.