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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:29:08+00:00 2026-05-28T03:29:08+00:00

Recently I have been trying to delve into advanced (well for me) programming concepts

  • 0

Recently I have been trying to delve into advanced (well for me) programming concepts like abstraction and functional programming etc. This has led me to experimenting w/ anon functions.

I have a situation where dynamically generated values are not being applied to a targeted element via an anonymous function using .css({}). I think it has something to do with false translations w/ object literals from my research.

Neither Chrome nor FF consoles are throwing any errors so here I am to ask the experts.

I made a fiddle, but it was not working very well. I am just going to link the resources involved on the dev site.

This is my dev site that I use to play/experiment and try out new things.

http://dev/kenstowell.net

The js file: http://dev.kenstowell.net/scripts/scripts.js

Everything can be found through the debugger console, of course.

Ok, so here is what the intended behavior is:

  1. On the (window).load, initDOM() is called.

    $(window).load(function(){
    //Style Initial Dom Elements
    initDOM();
    });

  2. Inside of initDom(), I attempt to set the top margin in relation to the parent container by calling setElemMargin() and supplying it with the appropriate params.

    setElemMarg("#main-content-one", "#intro-text", "#intro-text", "margin-top");

  3. setElemMarg() gets the height of the supplied args and uses them to calculate the margin to be set in the .css() map.

    var setElemMarg = function(elem1, elem2, elemTrgt, propName){
    var margH = (getH(elem1) - getH(elem2)) / 2;
    $(elemTrgt).css({propName : margH});
    console.log(elem1, elem2, elemTrgt, propName, margH);
    }

    var getH = function(elem){
    return $(elem).height();
    console.log($(elem).height());
    }

  4. apply the calculated margin to margin-top. (from above method)

    $(elemTrgt).css({propName : margH});

Thanks to anyone who looks at this. Please feel free to give me some constructive critique. Maybe some that you wish you had when you were a budding developer. 🙂

Ken

  • 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-28T03:29:09+00:00Added an answer on May 28, 2026 at 3:29 am

    The problem resides in your setElemMarg() function:

    var setElemMarg = function(elem1, elem2, elemTrgt, propName) {
        var margH = (getH(elem1) - getH(elem2)) / 2;
    
        $(elemTrgt).css({propName : margH});  // <-- Here.
    
        console.log(elem1, elem2, elemTrgt, propName, margH);
    }
    

    The literal object syntax you’re using in your call to css() results in jQuery trying to update a propName style property instead of the property whose name is stored in propName.

    You can use bracket notation to work around this issue:

    var styleProps = {};
    styleProps[propName] = margH;
    $(elemTrgt).css(styleProps);
    

    Or simply call the two arguments form of css():

    $(elemTrgt).css(propName, margH);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've recently been trying to port a C++ application. I believe I have all
Recently I have been studying recursion; how to write it, analyze it, etc. I
So I recently have been trying to incorporate more sub forms to make the
Recently I have been trying to make changes so I can do builds through
I've recently been trying out Ankhsvn and I quite like it, and more importantly,
recently I have been trying my hand at coding a game in C#. I'm
So recently I have been trying to set up a Vim-based iOS workflow. I
I'm a vim user and have recently been trying out emacs for fun. I
I have been trying out Splint with a C program I recently wrote and
I have been trying for a while to be able to access my recently

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.