Arrange elements based on the selected dropdown menu

I'm currently utilizing Twitter Bootstrap 2.3.2 along with the chosen plugin for select boxes. I have a question regarding how to align other elements based on the box with selected items.

Below, you can see two select boxes and content (elements) positioned under the select boxes.

Whenever I select some items, the box ends up overlapping the header "Source" as well as the items located beneath it. My goal is to have the elements shift down when options are selected and move back up when the options are deselected.

Here's the jsfiddle link

The HTML code looks like this:

<div id="filter">
    <div id="personFilter" class="form-group">
        <h4> Person filter </h4>
        <div id="personFilterContain">
            ...
        </div>
        <div id="personFilterNotContain">
            ...
        </div>
        <div class="checkbox">
            ...
        </div>
    </div>

    ...

<script>
$(document).ready(function () { 
    $('select[name=personNotContainSelect]', this).chosen();
    $('select[name=personContainSelect]', this).chosen();
});
</script>

CSS Styles:

#filter{
    text-align: center;
}

...

Answer №1

Assign ID attribute for a selection (for example, test):

<select id="test" data-placeholder= "address"...
 ...
</select>

Include a change event. Pay attention to #test_chosen, which has a similar ID attribute as the <select> element. The suffix _chosen is added by the plugin.

$('select[name=personContainSelect]', this).chosen().change(function(){           
        var h=$('#test_chosen').height()
        h+=56;//initial height of chosen            
        $('#personFilter').height(h)
    });

SOLUTION 2: CSS

#personFilter{
    height: auto;
}

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

Make sure to clear the timeout in JavaScript before re-calling the function again

Scenario: Whenever a user clicks on a cell within the "#test" table, the "update_func" function will run and repeat every 10 seconds. If the user clicks on the same cell or another cell, multiple instances of "update_func" start running simultaneously ev ...

Is there a way to develop a search script that can efficiently sift through the object using the provided script or a similar one?

$(document).ready(function(){ $.ajax({ dataType: 'jsonp', //data in jsonp contentType: "application/json; charset=utf-8", url: 'http://live.nhle.com/GameData/RegularSeasonScoreboardv3.jsonp', ...

A guide on retrieving a JSON response from a servlet and displaying it on a JSP page using jQuery Ajax

I am currently working on retrieving a JSON response that has been established within a servlet to be displayed on a JSP page. JSP page: <script> $(document).ready(function(){ $("#submitBut").click(function(){ var formData=ge ...

When casting a ray from the inside, the raycast does not collide with the mesh

In my latest project, I've created a unique scene that involves placing my camera inside a sphere geometry. var mat = new THREE.MeshBasicMaterial({map: THREE.ImageUtils.loadTexture('0.jpg') , overdraw:true, color: 0xffffff, wireframe: fal ...

Bootstrap dropdown menu experiencing functionality issues

I am facing an issue with implementing the javascript bootstrap file in my project. The dropdown menu is not working as expected even though I have saved bootstrap to my project folder. I have tried looking at other example codes and even copied and paste ...

What might be stopping Javascript from saving the value to the clipboard?

On my ASP.Net website, I am incorporating basic Javascript functionality. One particular task involves calculating a value and saving it in a hidden textbox, like this: <asp:LinkButton ID="LinkButtonShare" runat="server" CssClass="btn btn-success" OnC ...

Unable to utilize container-fluid on Chrome and tablet-sized screen due to compatibility issues

By using the container-fluid class, I have created a header that spans the entire front page. While this setup functions perfectly on Opera, Firefox, and Microsoft Edge, it falls short on Chrome, iPad, and mobile phone screens. Take a look at my code: &l ...

Tips for integrating map coordinates into a URL

In my React app, there is a Leaflet map that I want to update the URL dynamically with position information (latitude, longitude, and zoom) whenever the map is moved. For example: app.com/lat,lng,z/myroutes Furthermore, default values for lat, lng, z sho ...

Error in Next.js PDFtron Webviewer: ReferenceError - 'window' is not defined

Currently, I'm faced with a challenge in setting up a PDF viewer on my nextjs static page. Having recently ventured into Next.js, I'm seeking assistance from you guys to resolve this issue or suggest an alternative approach. While trying to imple ...

Struggling to make background image behave as desired in CSS

After spending hours scouring forums, I still haven't been able to solve this issue. I am trying to make one of my divs serve as the background for my entire website. Additionally, I want it to start from a specific point and not cover the entire pag ...

Divs are shown as the user scrolls, not only when they are in view

Currently, I am in the process of enhancing my online portfolio by integrating a bar graph feature. However, I have encountered an issue with its functionality. The goal is for the bar graph to display only when it comes into view during scrolling. Althoug ...

Include additional select fields created through PHP

I have a dropdown menu on my HTML page that is populated by PHP from a MySQL database. echo "<select name='author_id[]' size='1'>"; foreach ($authors as $author) { echo "<option value=$author[id]>$author[ ...

"Learn how to handle exceptions in Nest JS when checking for existing users in MongoDB and creating a new user if the user does

Below is the implementation of the addUser method in users.service.ts - // Function to add a single user async addUser(createUserDTO: CreateUserDTO): Promise<User> { const newUser = await this.userModel(createUserDTO); return newUser.save() ...

The variable req.body.username is not defined in the context of JavaScript

I am completely new to JS, Angular.js and node.js. I am currently working on a login-register project but facing a minor issue. Below is my code: login.ctrl.js: var app = angular.module('login-register', []); app.factory('UserLog', ...

Exploring CSS Shapes: Unveiling the secrets behind the star. What's the mechanism at

https://i.stack.imgur.com/0BgQr.png Take a look at the code snippet below showcasing The Shapes of CSS. I'm interested in delving into the intricacies of these CSS properties. How exactly do shapes in CSS function? This includes pseudo CSS, borders, ...

Clicking on the modal will trigger its closure

Is there a way to prevent Bootstrap 4 modal from closing when the user tries to leave the page but clicks on it instead? I have attempted various solutions from this platform, but none have worked for me. I am running out of ideas. This snippet shows my ...

Improving Zen Coding to integrate with JavaScript files on Sublime Text2

Sublime Text2 is hands down my go-to editor, except for one minor hiccup - the Zen Coding plugin only works with CSS and HTML files. There are plenty of times where I'd love to use Zen Coding with JavaScript or other file types, like incorporating HTM ...

What causes the sudden jump in width during a transition?

I'm having trouble with setting transitions. Everything seems to be in order and almost working, but I'm experiencing a "jumping" effect: instead of smoothly transitioning the width from 100% to 100px, it jumps from 100% to "min-content" to 100px ...

Creating an undo feature for a dynamically generated checklist of checkboxes

I am using a combination of javascript/jquery and html to dynamically populate the page with checkboxes. When you click "add", a new checkbox is created. I am now looking for a way to add an undo button that would delete the last checkbox created. Here is ...

Perform both creation and updating tasks within a single transaction using sequelize

Is it feasible to add a new row and update it within the same sequelize transaction? Here's what I've tried: let transaction; try { transaction = await dbcontext.sequelize.transaction(); const newEmployee = await dbcontext.Empl ...