Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation nested $.each doesn't work in IE8

    Hi,
    I've got a strange problem:
    with an object like


    Code:
     {"level1":[{"values":{"level2":"valuelevel2","level2a":"valuelevel2a"},"index":"index1"},{"values":{"level2":"valuelevel2","level2a":"valuelevel2a"},"index":"index1"}]}
    if I want to use a nested jquery each, IE8 prints only one 'ok' running this code [reporting an error]:



    Code:
     $.each(result, function(i, result_wrapper){
                $.each(result_wrapper, function(i, result_values){
                    if(result_values["index"] == 'index1' ) {
                        document.write("ok");
                    } else {
                        document.write("ko");
                    }
                });
            });

    This works with FF and Chrome.
    Why? Is there a workaround?

    Thanks in advance

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,395
    Thanks
    12
    Thanked 569 Times in 562 Posts
    Never ever ever ... ever again ... use document.write

    It will erase the DOM if invoked after page load and create a new one ... including your Javascript code which will of course not be available any more then.

    Please try to get used to DOM manipulation methods like .innerHTML, .createElement, .append, .insertBefore etc.

  • #3
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by devnull69 View Post
    Never ever ever ... ever again ... use document.write

    It will erase the DOM if invoked after page load and create a new one ... including your Javascript code which will of course not be available any more then.

    Please try to get used to DOM manipulation methods like .innerHTML, .createElement, .append, .insertBefore etc.
    I know....I use it to debug instead console.log. The problem isn't the "document.write". Any suggestion?


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •