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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:56:54+00:00 2026-06-08T17:56:54+00:00

If uncomment body.children().each(calc_deep(1)); then i get TypeError: Object [object Window] has no method ‘attr’

  • 0

If uncomment body.children().each(calc_deep(1)); then i get TypeError: Object [object Window] has no method 'attr' on the parseInt(deepest.attr('deep')) string, but without uncomment you can check in console that you can call deepest.attr('deep'). What is that?

    var deepest;
    var calc_deep = function(i)
    {
        $(this).attr('deep',i);
        if(i>parseInt(deepest.attr('deep')))
            deepest=this;
        $(this).children().each(calc_deep(i+1));
    }
    var find_deepest = function()
    {
         body=$('body').children().eq(0);         
         body.attr('deep',0);
         deepest=body;
         //body.children().each(calc_deep(1));
    }
    find_deepest();
  • 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-08T17:56:55+00:00Added an answer on June 8, 2026 at 5:56 pm

    The first deepest is the variable body, which is a jQuery object. Later, when you assign deepest to this, it is a regular DOM element, which has no attr function.

    You have a bigger problem – this is not pointing the element you think it is. Call $(this).children().each(calc_deep); without the argument to the function. To get the depth, just get it from the parent. You are calling the function calc_deep and passing the (non-existant) return value to each. You want to pass the function itself to each.

    var deepest, index;
    var calc_deep = function() {
        var $this = $(this); //cache jQuery this
        var i = $this.parent().data("deep") + 1;
        $this.data('deep', i);
        if (i > index) {
            deepest = $this;
            index = i;
        }
        $this.children().each(calc_deep);
    }
    var find_deepest = function() {
        body = $('body').children().eq(0);
        body.data('deep', 0);
        index = 0;
        deepest = body;
        body.children().each(calc_deep);
    }
    find_deepest();
    

    jsFiddle demo

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

Sidebar

Related Questions

Whenevr i uncomment the second line then the tabs are not shown. inform is
Whenever I uncomment the ScriptAliasMatch line, I get a 500 error. I am not
I use git under window and I want do some operation after each push,
When I enable (uncomment) this line of code I get a SIGABRT crash -
Given a body of HTML, is there any function out there someone has written
When I uncomment the alert the data is there... like: { 'Huishoudelijke hulp': 'Huishoudelijke
This is my program - (void)viewDidLoad { [super viewDidLoad]; // Uncomment the following line
i'm using MAMP and want to activate xdebug. i've uncomment the following row in
I'm having problems the following code gives me no results. however if I uncomment
Bazaar has a wonderful uncommit command, which simply undoes the last commit. Is there

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.