Is it possible to apply SlideToggle() to Div elements that have their Display property set to Table-Cell?

I am facing an issue on my web page where I have a series of div elements styled with display: table and their child div elements styled with display: table-cell. I am looking to use slideToggle() on a specific cell to change its content. However, I have come across information suggesting that slideToggle() might not work as expected with elements set to table-cell.

Firstly, I would like to confirm if it is true that slideToggle() does not fully support Table-Cell objects?

Secondly, before making drastic changes to my design to avoid the use of Table-Cells, I am curious if there is a workaround that I can implement to achieve the desired functionality?

The provided code snippet showcases the undesired behavior I am experiencing. Instead of a smooth sliding transition, the cell abruptly appears next to the previous cell that is meant to disappear, failing to slide up vertically as intended.

<!DOCTYPE html>
<html>
<head>
    <title>Test</title>
    <style type="text/css">

.container {
    display: table;
}

.cell {
    display: table-cell;
}

    </style>
</head>
<body>

    <button onclick="$('.cell').slideToggle('slow'); return false;" >Click Me</button>
    <div class="container">
        <div class="cell">Here is a test</div>
        <div class="cell" style="display: none">Test2</div> 
    </div>

    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="common/js/jquery-2.1.4.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="common/bootstrap/js/bootstrap.min.js"></script>
    <!-- Other Scripts -->
    <script src="common/bootstrap-select/js/bootstrap-select.min.js"></script>

</body>
</html>

Here's the link to the code on a fiddle for reference: https://jsfiddle.net/gdbjohnson/8x8e1gyx/

Answer №1

Finding a solution to this issue can be quite challenging. The behavior of slideToggle when used on table-cell elements can be problematic, as it restores the element to its previous state. According to the documentation:

The display property is saved and restored as needed. If an element has a display value of inline, then is hidden and shown, it will once again be displayed inline. When the height reaches 0 after a hiding animation, the display style property is set to none to ensure that the element no longer affects the layout of the page.

The main issue lies in the fact that the animation of the element may not function as expected, as slideToggle attempts to animate the height of the element. However, the height of a table-cell cannot be reduced beyond the size of its content.

In conclusion, while technically slideToggle can be applied to table-cell elements, it may not produce the desired animation effect.

For further information, you can refer to: .slideToggle()

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

PHP form does not seem to be vulnerable to cross-site scripting attacks

On one of my web pages, I have a form with an action php page using the following html syntax: <form name="form" action="test.php" method="get"> I decided to make it more secure by modifying it to: <form name="form" action="<?php echo htmlsp ...

Incorporate the value of a variable from the .gs file into a personalized HTML sidebar

In my google sheet, I have set up a custom sidebar through scripting. Within this sidebar, I aim to showcase the value from column I in the currently active row. I've successfully created a script that captures and stores the 'I' variable ...

Unable to establish proper functionality of username variables in Node.js chat application

For my latest project, I am developing a chat application in node.js following a tutorial from socket.io. The main objective of the app is to allow users to input their username along with a message, which will then be displayed as "username: message" in t ...

Delete the "img" and "a" elements from the content within the specified node

Is it possible to only extract text from my HTML content? var sb = new StringBuilder(); doc.LoadHtml(inputHTml); foreach (var node in Doc.DocumentNode.ChildNodes) { if (node.Name == "strong" || node.Name == "#text" || node.Name == "br" || no ...

What causes the form to be submitted when the text input is changed?

I'm puzzled by the behavior of this code snippet that triggers form submission when the input value changes: <form> <input type="text" onchange="submit();"> </form> Typically, I would expect something along t ...

How can we focus href on a <div> using CMS in PHP?

I am currently in the process of learning PHP and simultaneously tackling a redesign of a custom CMS. The CMS is written in PHP, and I have already revamped the default menu using CSS to incorporate a side slide effect. However, my next challenge is to en ...

"Explore the functionalities of Drupal's innovative Menu module: How sub-sub menus can take precedence over sub-menus

When visiting , I noticed that the Nice Menu module for Drupal is not displaying sub-sub menus properly. If you navigate to the first item in the menu and then select the first one in the sub-menu (Facilities->Spring->Calendar), you'll see that ...

SQL inputs with information that updates automatically / autofill SQL input boxes

Is it feasible to create a webpage that can connect to an SQL database, retrieve information from a table, and display it in a text box based on the input provided in another text box? Essentially, I am looking for a way to enable autofill functionality. I ...

Extract data from the DOM in JSON format

Upon pressing Ctrl+U, I discovered the following JSON in the DOM of my page: <script type="text/x-magento-init"> { "#country": { "regionUpdater": { "optionalRegionAllowed": true, "regionL ...

Sending form data using Ajax

My concern is quite straightforward - I am using jquery and ajax to submit a form. When the button is clicked, the data gets sent to the database. The question is - if the user clicks the submit button twice, there will be two entries in the database. Ho ...

Change the position of an array element when displayed on an HTML page

I'm trying to figure out a way to manipulate the position of an HTML element that is stored inside an array. The issue I am facing is that my code generates a new div every time a specific function is called, and this div has a class applied to it for ...

Can someone please help me figure out why the "setInterval" function in my script isn't functioning as expected?

I've been experimenting with controlling the refresh rate of drawn objects in a canvas using JavaScript. Even after going through the tutorials and examples on w3.school, I'm still unsure why the "setInterval" function is not executing the "gener ...

Is there a feature that allows the phone number on the website to be dialed automatically as soon as the page loads?

Creating a marketing strategy for a client who wants the phone number on his website to automatically initiate a call as soon as visitors arrive through a marketing link. Is there a way to accomplish this without requiring an additional step of clicking "C ...

What might be causing the overflow of my page width by my navbar?

I am currently working on creating a product landing page for freecodecamp, and I'm facing some issues with my navbar - the first element I need to get right. Could you help me identify what's wrong with my code? Additionally, I would like to ad ...

Efficient File Upload Feature Compatible with all Browsers, Including Internet Explorer versions 7, 8, and 9

Can someone assist me with a problem I'm facing? I need a code script that enables multiple file uploading on all browsers. While HTML5 supports Chrome and Mozilla Firefox, it does not support IE. I am looking for a script/jquery solution that works ...

Error message "Unexpected token" occurs when using jQuery bxSlider

Greetings to all, I have implemented jQuery bxSlider in my project and here is the code snippet: jQuery(document).ready(function() { jQuery('.abc').bxSlider(function() { mode: 'fade', ...

Engaging with a remotely loaded HTML in a JQUERY UI Dialog

My Experience with JQuery UI Plugin For a while now, I've been utilizing the JQuery UI plugin to create dynamic dialog boxes that load content on the go. Imagine this scenario: I load an HTML document that showcases various selectable items with che ...

How can DataTables (JQuery) filter multiple columns using a text box with data stored in an array?

I've been attempting to create a multi-column filter similar to what's shown on this page () using an array containing all the data (referred to as 'my_array_data'). However, I'm facing issues with displaying those filter text boxe ...

Missing HTML escape sequences following conversion to a string

The Android test was successfully run using the following code: public static void test() { String text="<html>" + "<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=us-ascii\" /> ...

What could be causing the discrepancy in functionality between Safari and Chrome for my overlay feature?

After testing the image hover overlay feature on various platforms such as desktop and Android devices, it has come to my attention that it does not function correctly on Safari. Specifically, the feature does not work on Apple devices like iPhone, iPad, a ...