Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 736225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:34:50+00:00 2026-05-14T07:34:50+00:00

Please have a look on the code below .. <div id=click_me>Save</div> <div id=blocks_sortable> <div

  • 0

Please have a look on the code below ..

                <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>

<script>
    $("#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).attr("id")+"&items=";

                //trying to select all the items of the current Block
                var result2 = $(block+" > div");                        
                    for(var j=0; j<result2.length; j++){
                        var item = result2[j];

                        str2 += $(item).attr("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);
            }
    });
</script>

It is not working. Is there any easier and working solution to get these ids. Please help.

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T07:34:50+00:00Added an answer on May 14, 2026 at 7:34 am

    jQuery map function is your friend

    $.map( 
        $("#blocks_sortable > div"),
        function(elementOfArray){
            var block = $(elementOfArray);
            var children = $.map(
                $("div[id]", block),
                function( eoa ){
                    return eoa.id;
                }).join(",");
    
            return elementOfArray.id + "=" + children;
        }
    ).join(",");
    

    Will return "block_1=item_1,item_2,item_3,block_2=item_4,item_5,item_6", which gets you much closer to where you’re going (I think).

    EDIT: Solution and source here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 393k
  • Answers 393k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You don't have to do anything: when the web.config file… May 15, 2026 at 1:54 am
  • Editorial Team
    Editorial Team added an answer A lambda term represents a function as a value. It… May 15, 2026 at 1:54 am
  • Editorial Team
    Editorial Team added an answer Package it as an extra: i.putExtra("MyReallyCoolContactID", id); Then, ContactDetails can… May 15, 2026 at 1:54 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.