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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:02:50+00:00 2026-06-15T21:02:50+00:00

I have some jquery code I’m using to set a div height based on

  • 0

I have some jquery code I’m using to set a div height based on its width. JSFiddle example here.

Everything works as is, but what I want is a function that is reusable, so that I’m not creating the exact same function for every unique id. The code is only good for the #bigHug div at the moment, but I want to be able to do something like $('#biggerHug').setHeight(1.8) in the .ready and .resize functions and to have the height set for the provided id.

I was attempting a solution by placing $(this).width() instead of $('#bigHug').width() in the setHeight function, but everything “broke”. The div wouldn’t show up on load or window resize. I was thinking it had to do with the $(this) referring to the $(window).ready instead of the $('#bigHug').setHeight(1.8).

Thoughts?

  • 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-15T21:02:52+00:00Added an answer on June 15, 2026 at 9:02 pm

    Try this:

    function setHeight(ratio, elem ) {
        $elem = $(elem);
        var divWidth = $elem.width();
        var divHeight = divWidth / ratio;
        $elem.height(divHeight);
    }
    
    
    $(window).ready(function() {
        setHeight(1.8, '#bigHug');
    });
    
    $(window).resize(function() {
        setHeight(1.8, '#bigHug');
    });​
    

    DEMO

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

Sidebar

Related Questions

I have some jQuery code that is having difficulty running because I'm using it
I have some jQuery code which retrieves content using getJSON(). There are n JSON
I have some JQuery code that shows or hides a div. $(div#extraControls).show(); // OR
I have some jquery code that displays and hides a div when a link
I have some jquery code inserting a div like this function popUpBox(){ $(.openBox).click(function(){ var
i have some jquery code here that works fine in firefox but when i
I have written some jquery code to select the div which is grandchild of
I have some jQuery code like this : $(function($) { $('input.autonumeric').autoNumeric({aSep: ',', aDec: '.',vMax:'1000000000000'});
I have some jquery code that is doing an ajax lookup and returning comma
I have some jQuery code that highlights a link when clicked, and changes the

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.