SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Simple jQuery

  1. #1
    SitePoint Addict
    Join Date
    Sep 2008
    Posts
    341
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple jQuery

    Why does this simple jQuery not work?

    http://page-test.co.uk/jq.html

    It should result in this:

    <div class="main">
    </div>
    <div>1</div>
    <div>2</div>
    <div>3</div>

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    6,056
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    Hi,

    The problem is caused by the string variable stored_html.
    You can do what you want by making it an array.

    Code JavaScript:
    var stored_html = new Array();
     
    $(".main > div").each(function() {
      stored_html.push($(this));
    });
     
    $(stored_html.reverse()).each(function(){
      $(this).insertAfter($(this).parent());
    });

    Obviously, this is not the best way to accomplish the small task you describe above, but as I'm sure that there's a lot more going on in your script that this, I tried to keep your code as it was.

    I would be grateful if anyone else reading this can give a clearer insight as to what exactly was not working in the original code.
    Also, I would be glad to find out if there is a better way of doing this (I'm sure there is )


Bookmarks

Posting Permissions

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