Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
<!--[if IE]>
  <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
  article, aside, figure, footer, header, hgroup, 
  menu, nav, section { display: block; }
</style>
</head>
<body>
                <div id="click_me">Save</div> 
<div id="blocks_sortable">
    <div id="block_1">
        <h2>Block 1</h2>
        <div class="items_sortable connectedSortable">
            <div id="item_1"> 
                <span>Item 1</span></div>   
            <div id="item_2"> 
                <span>Item 2</span></div>
            <div id="item_3"> 
                <span>Item 3</span></div>
        </div>
    </div>  
    <div id="block_2">
        <h2>Block 2</h2>
        <div class="items_sortable connectedSortable">
            <div id="item_4"> 
                <span>Item 4</span></div>   
            <div id="item_5"> 
                <span>Item 5</span></div>
            <div id="item_6"> 
                <span>Item 6</span></div>
        </div>
    </div>
</div>
</body>
</html>
 
$("#click_me").click(function() {
            var result = $("#blocks_sortable > div");
            for(var i=0; i<result.length; i++){
                var str = "";
                var str2 = "";
                var block = result[i]; //div object
                //retrieve block id and create the string with id
                str += "block="+ block.id +"&items=";
                //trying to select all the items of the current Block
                var result2 = $("#" + block.id + "> div > div");
                    for(var j=0; j<result2.length; j++){
                        var item = result2[j];
                        str2 += item.id +",";
                    } //end for items
                str = str+str2;
                // looking for a final string in the format of .. block=block_1&items=item_1,item_2,item_3 for loop 1
                alert(str);
            }
    });
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers