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 6190681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:37:54+00:00 2026-05-24T02:37:54+00:00

UPDATE 1: Here is more of the script: $(.favorites).sortable( {update:function() { var that =

  • 0

UPDATE 1:

Here is more of the script:

$(".favorites").sortable(
    {update:function() {

    var that = this;

    var urls = ""; 
    var texts = "";

    $.map($(".favorites a"), function(elt) { 
        urls += "url=" + elt.href + "&";
        texts += "text=" + $(elt).html() + "&"; 
    }); 

    $.ajax({
        url: 'favorites.asmx/save',
        type: 'POST',
        data: { strItems:$(that).sortable("serialize",{key:'item'}), strURLs:urls.substr(0,urls.length - 1), strTexts:texts.substr(0,texts.length - 1) },
        error: function(xhr, status, error) {
                    console.log(xhr.responseText); 
        },
        success: function() {
            console.log("Values sent:- strURLs: " + urls.substr(0,urls.length - 1));
        }
    });

ORIGINAL QUESTION:

I have the following script which works, but I don’t understand it:

$.map($(".favorites a"), function(elt) { 
    urls += "url=" + elt.href + "&";
    texts += "text=" + $(elt).html() + "&"; 
}); 

I understand the basic examples in this link: http://api.jquery.com/jQuery.map/, but I don’t understand the script I have posted above.

  • 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-24T02:37:57+00:00Added an answer on May 24, 2026 at 2:37 am

    The purpose of map is to create an array by taking each of the elements of the array or object you pass into it and filtering them through the function you give it; the function’s return values are collected together into the resulting array, which is the return value of map.

    That code isn’t doing that. It’s not returning anything from the iterator, and it’s not using the resultant array. Basically it’s just re-invented .each by abusing map. That script should be:

    $(".favorites a").each(function() { 
        urls += "url=" + this.href + "&";
        texts += "text=" + $(this).html() + "&"; 
    });
    

    (Note that I’m assuming here that urls and texts have been declared and initialized prior to the code you quoted.)

    Here’s an example of a correct use of map:

    var hrefs = $.map($(".favorites a"), function(elt) {
        return elt.href;
    });
    // hrefs is now an array containing the `href`s of all of the links
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

UPDATE: So pretty much everyone here has told me that I just need to
Here is my chunk of code: var update_shipping_methods = function(methods) { $(methods).each( function(i) {
Update: This question was an epic failure, but here's the working solution. It's based
This question sort of covers both ServerFault.com and here, but this seems more programming
Scenario 1 (That Works) This is a POC i created. I have a script
UPDATE : Some have said that they were able to get more than 1
Update I summarized the question and its answers here My objective is to detect
Replaces Question: Update multiple rows into SQL table Here's a Code Snippet to update
Update In the wiki spirit of StackOverflow, here's an update: I spiked Joe White's
I am going nuts here trying to resolve a cascading update/delete issue :-) I

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.