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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:36:42+00:00 2026-06-08T11:36:42+00:00

When I try to return object from the function and assign it to smalls

  • 0

When I try to return object from the function and assign it to smalls variable, the variable smalls is empty as it’s length is returned as 0.

var smalls = function(){
        var table = $("#box-table-a");
        return table.find("small");
    }, smallContent;
    for(var i = 0; i<smalls.length; i++){
        smallContent = smalls[i].innerHTML;
        smalls[i].parentElement.className += "relative";
        smalls[i].className += "form-absolute-right";
        smalls[i].innerHTML = "<span class='bubble'>" + smallContent + "<span>";
    }

While this works and variable smalls has the desired length.

    var table = $("#box-table-a");
    var smalls = table.find("small");       //fetch the tr's with <small> tag
    var smallContent;
    for(var i = 0; i<smalls.length; i++){
        smallContent = smalls[i].innerHTML;
        smalls[i].parentElement.className += "relative";
        smalls[i].className += "form-absolute-right";
        smalls[i].innerHTML = "<span class='bubble'>" + smallContent + "<span>";
    }

From the knowledge I have on Javascript, one can assign function to a variable. What am I doing wrong?

  • 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-08T11:36:43+00:00Added an answer on June 8, 2026 at 11:36 am

    As others have mentioned, you loop over a function reference and not the result from executing smalls.

    Yet, as you use jQuery, you can write shorter/simpler code:

    var smalls = $("#box-table-a").find("small"); // this var really contains the elements
    smalls.addClass("form-absolute-right").wrapInner("<span class='bubble' />");
    smalls.parent().addClass("relative");
    

    This has various advantages:

    • the classes are simply added to the list and you don’t have to worry about the whitespaces.
    • wrapInner does preserve the DOM (with all listeners etc) instead of messing with html strings
    • the parent() traversing methods uniques the set, so elements with more than one table-box do get only one class
    • you don’t need a loop at all, jQuery methods are executed on every item in the set.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I assign a variable(var) to a json object which is returned from
I'm getting undefined when i try to return the oject from the function. And
When I try to get the custom attributes from an object the function returns
I have a code like that: User = function(){} User.a = function(){ return try;
I am trying to have a function grab an object from a php file
I'm wondering if I can return an object from json_encode() to JQuery. If I
I'm trying to return a dictionary from a function. I believe the function is
I'm using this function to return a value from multiple databases across three SQL
Lets say I have the code: class NoneDict(dict): def __getitem__(self, name): try: return super(NoneDict,
I have my own templatetag: @register.inclusion_tag('path_to_module.html', takes_context=True) def getmodule(context, token): try: return slow_function(params) except

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.