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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:53:41+00:00 2026-06-18T04:53:41+00:00

The one without callback function jsFiddle produces wrong outcome. The console log should show

  • 0

The one without callback function jsFiddle produces wrong outcome. The console log should show i=0 & j=0 as indicated “group[0] record[0]”. because I am trying to find the dd/dt set: “Book: a book name”.

I understand I need to include a callback function similar to this post. However I don’t seem to understand how to insert the function correctly. Here is the one I am working on:

jsfiddle w/ callback

var arrDL = [];
$("dl").each(function(i) {     
   arrDL[i] = [];
   $(this).children("dt").each(function(j){ 
       function(n){
            return function(){
                var $this = $(this); 

                arrDL[n][j] = {
                   title: $this.text(),
                   description: $this.next("dd").text()
                };

                if($this.text() == "Book:" && $this.next("dd").text() == "another book name"){
                   console.log("group 0 record 0: " + n + '-' + j);
                };
           };    
      }(n);               
  });    
});

Thanks for your help.

  • 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-06-18T04:53:42+00:00Added an answer on June 18, 2026 at 4:53 am

    You are creating a function inside the function (inside the callback for the inner each) and returning it. You are executing the outer function, but it returns a function reference which you don’t execute, so the code inside the inner function will never run.

    Also you are sending the variable n into the outer function, but it’s never defined anywhere, so it will just be undefined.

    Actually there is no need for either the outer or the inner function, just put the code in the callback for the each:

    var arrDL = [];
    $("dl").each(function(i) {     
      arrDL[i] = [];
      $(this).children("dt").each(function(j){ 
        var $this = $(this);
        arrDL[i][j] = {
          title: $this.text(),
          description: $this.next("dd").text()
        };
        if($this.text() == "Book:" && $this.next("dd").text() == "another book name"){
          console.log("group 0 record 0: " + i + '-' + j);
        };
      });    
    });
    

    The result that you get is correct, the description “another book name” is found in the second group, not the first group.

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

Sidebar

Related Questions

What I need is to automatically call a function (callback function) inside one or
How does one return from a closure, without returning from the containing function? In
If I want something to occur after the .show() event (the one without the
I registered a CALLBACK using: gluTessCallback(tess, GLU_TESS_COMBINE, (GLvoid(*)()) &scbCombine); Where scbCombine is a function
I'm trying to make an address redirect to another one without actually changing the
I want to fetch the id of a one-to-one relationship without loading the entire
I want to modify the index of one (text) file without having to change
One recommends me the following code apparently only in .zshrc without explaining its purpose
One of BoundField in my GridView has a very long string without space. I
How can you use Git without Sudo in multiple accounts in one Ubuntu? My

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.