Click a button to adjust the height of an element

My webpage features a dashboard with tabs on the left and corresponding content on the right. To ensure proper alignment, I have utilized Bootstrap to create two columns - one for the tabs and one for the content. However, I am facing an issue where the border of the tabs does not cover the full height of the content on the right side. In an attempt to fix this, I wrote a jQuery function that sets the height of the last tab ("#ws"), but unfortunately, it only works on page load and not on button click.

In short

1) Visit

2) Take note of the border-right of the tab and how its height matches the content on the right

3) Click on any other tab such as "address book" and observe how the height decreases

The goal is to maintain a consistent height matching the content on the right-hand side.

Here is a snippet of my HTML:

 <div class="col-md-2 col-sm-3 hidden-xs nopadding">
    <div id="dtnavs">
    <div class="col-md-12 tabtxt active" id="dasht">My Dashboard</div>
    <div class="col-md-12 tabtxt" id="cartt">My Cart</div>
    <div class="col-md-12 tabtxt" id="addresst">Address Book</div>
    <div class="col-md-12 tabtxt" id="ordert">My Orders</div>
    <div class="col-md-12 tabtxt" id="wisht">My Wishlist</div>
    <div class="col-md-12 tabtxt" id="newst">Newsletters</div>
    </div>
    <div class="col-md-12 tabtxt" id="ws"></div><!--set height dynamically-->
  </div>

Upon click:

  $("#addresst,#mtab3").click(function() {
    $('#dashboardtab,#carttab,#ordertab,#wishtab,#newslettertab,#video').slideUp(500);
    $('#addtab').slideDown(500);
    $(".dashnav").find(".active").removeClass("active");
    $(this).addClass("active");    
    setwsheight("#addtab");
    $(".ccatname,#bcactive").text("Address Book");
    console.log(this);
    return false;
});  

Function setwsheight();

function setwsheight(sh){
    $('#ws').delay(1000).height($(sh).height()-$('#dtnavs').height());
    var str = "$('#ws').height($("+sh+").height()-$('#dtnavs').height())";
    console.log(str);
    console.log(sh+" height : "+$(sh).height());
    console.log("dtnavs height : "+$('#dtnavs').height());
    console.log("WS height :" +$('#ws').height());
};

Answer №1

Not using jQuery
I made some adjustments to your HTML code

Delete the class "left40" from the content tab

Add this CSS to the parent content of your content side:

col-md-10 col-sm-9 col-xs-12 nopadding

.selector {
    border-left: 1px solid #ccc;
    margin-left: -1px;
    padding: 0 0 0 40px;
}

Apply this CSS to the tab content:

col-md-2 col-sm-3 hidden-xs nopadding

.selector{
    background: #fff none repeat scroll 0 0;
    position: relative;
    z-index: 999999;
}

Answer №2

Give this a shot.

var calculateNewHeight = your equation;
$('#ws').animate({
   height: calculateNewHeight + "your measurement unit"
}, yourDelay, function(){});

If that doesn't resolve the issue, consider setting the #ws element's position property to absolute in a CSS stylesheet, along with implementing the code provided in this response.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Initializing Angular variables

My Angular controller has a variable called $scope.abc. The backend I'm using is Sails. The initial value of $scope.abc can be set by the backend when the page is first generated. Once the page is displayed, the user may or may not change this value ...

The div with a 'inline-block' display and maximum width appears to be wider than needed after a line break

The red div labeled as inline-block-1 in the jsFiddle takes up more space than needed for the text. Is there a way to eliminate the extra space, making it resemble the green inline-block-2 without removing the max-width and avoiding hard-coding width? Feel ...

After developing a new like button feature, I noticed that upon refreshing the page, the total like count resets to zero

Imagine creating a like button that, when clicked, first checks if the user is logged in. Only users who are logged in can click the like button and have the like count increase by 1. However, every time the page is refreshed, the like count resets to 0. W ...

Enhance your table layout with Bootstrap 3 by adjusting textarea size to fill

I am currently in the process of developing a forum and bulletin board software. I am facing some challenges while trying to integrate a reply section into the thread page. You can view what I have implemented so far here. Html: <div class="panel pane ...

The only thing visible on my project is the homepage, void of any buttons or additional pages

After completing this school project, I believed that everything was done correctly. However, as I faced issues with the code, I decided to seek help and share my app.js and bin section for clarification. Starting it with npm on the localhost as shown in ...

python Chromium process leak initiated by requests-html

My program is experiencing a crash due to a memory leak before it can complete the loop. The script I am using: from requests_html import HTMLSession from bs4 import BeautifulSoup import requests for x in range(9376, 23534): session = HTMLSession() ...

When attempting to import vue.js within a JavaScript file in a Django application, an error of 'Uncaught SyntaxError: Cannot use import statement outside a module' is encountered

Currently, I am delving into incorporating vue.js into a live django project and have come across a stumbling block. After setting up npm in the venv environment and installing the vue package, my next step is to create a Vue object within a js file using ...

Angular JS sending a message to various views, including a pop-up modal

One of the services I have created is designed to manage message broadcasting to controllers that require it. The service implementation: .factory('mySharedService', function($rootScope) { var sharedService = {}; sharedService.message = &a ...

The @Input() function is failing to display or fetch the latest value that was passed

I am currently working on an angular project, and I've encountered a situation where I'm attempting to send a value from a parent component to a child component using the @Input() decorator. Despite my efforts, the child component continues to di ...

The form will only display results after the "Submit" button is clicked twice

Recently, I built a flask website where the form and results are displayed on the same page. However, there seems to be an issue that arises upon clicking the 'submit' button for the first time after running 'flask run'. The error messa ...

Unable to Click on Selenium Element

When a link is clicked on a website, the URL remains unchanged but a popup appears on the screen containing elements that can only be accessed after running driver.switchTo().defaultContent(). To access these elements, I have used a javascript executor com ...

What is the best way to clear an array?

Yesterday I had a query regarding JSON Check out this link for details: How to return an array from jQuery ajax success function and use it in a loop? One of the suggested answers included this script: setInterval(updateTimestamps,30000); var ids = new ...

css: positioning images with overlap in a responsive layout

Two divs have been created with background images, both displaying the same image but in different colors - one grey and the other green. These images are waveforms. Initially, only the grey image (div1) is visible while the green image (div2) remains hid ...

I'm looking to achieve the same effect repeatedly with JQuery every time I click

Below is my JQuery code. I have implemented functionality where clicking on the '+' link will slide down a text box, which is working fine. However, I want the same effect to occur every time the '+' link is clicked again. Can anyone he ...

Troubleshooting: The issue of Vue JS not successfully navigating between web

After countless attempts, I am still struggling to get my Firebase login function to appropriately switch the component upon signing in. I urgently need assistance with configuring my router to seamlessly transition to the next page once the sign-in proces ...

Issue with `styles` argument after updating from Material version 4 to 5: MUI

After recently upgrading from Material V4 to V5, I encountered the following error message: MUI: The `styles` argument provided is invalid. You are providing a function without a theme in the context. One of the parent elements needs to use a ThemeProvider ...

Can someone provide a method to automatically align bootstrap 5 footers within a set of cards?

Trying out this HTML code in Bootstrap 5, I noticed that the third column appears longer than the first two columns: <!-- bootstrap scripts --> <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_ ...

What's the best way to correct a word that is positioned at the bottom of a banner image?

https://i.sstatic.net/3gSoi.pngI am a newcomer to all of this. I have a banner image and I want to position a word at the bottom center of the banner. I've tried using padding, position, and text-align, but it's not responsive - when I widen the ...

Clicking on a date in Vue.js Fullcalendar

My goal is to retrieve a date value from the onDateClick function of fullCalendar using vue.js and then pass this data to a prop that can be stored in my backend via Laravel. However, I am encountering various undefined errors no matter how I approach th ...

The process of retrieving CSS attributes from a control found by XPath using Selenium IDE

During my Selenium IDE script execution, I am looking to identify and handle an error state. This specific error state is visually highlighted on the page with a select control changing its background color to a light shade of red. The xpath for the selec ...