The CSS on the page does not update when called within a JavaScript function

Just joined and this is my first question, so please go easy :).

I've encountered a problem with changing the CSS of elements and their refresh. I'm working on a webforms application with AJAX requests. The issue I'm facing is that when someone selects a report from a tree view, it should display a loading gif and then show the data once it's received. Everything works fine on Firefox and Opera, but not on IE, Chrome, or Safari. Here's the code snippet:

This is the method that runs when a tree node is clicked this.hideElements(); var id = node.getId().substr(2);

var client = new CAjaxClient();
var data;

client.addParameter(new CKeyValuePair('ReportID', id));

client.postCallBack('/ajaxpages/Reports.aspx', 'GetReportFilters', this.dataRecieved);

filterGenerator.setReportID(id);

This is the hideElements() method

$('#FiltersContainer').css('visibility', 'hidden');
$('#ActionsContainer').css('visibility', 'hidden');
$('#loadingDiv').css('visibility', 'visible');
$("input[id$='Date']").parent().css('visibility', 'hidden');

This is the AJAX postBack method

if (this.readyState == 4 && this.status == 200) {
$('#FiltersContainer').css('visibility', 'visible');
$('#ActionsContainer').css('visibility', 'visible');
$('#loadingDiv').css('visibility', 'hidden');
var data = eval(this.responseText);
filterGenerator.processFiltersData(data);

The data is returned correctly, it's just during the request time, the browser seems frozen and when the data returns, the CSS state is at the end of the process. The loading div is never shown. I've tried forcing a redraw with domelement.style changes, but it had no effect. When I execute the code in Chrome debugger line by line, everything works perfectly. Any help would be appreciated.

Here's the HTML code snippet (vio: TreeView is our own ASP control):

<div id="pageHeader" style="display:inline-block">

        <div id="headerImageDiv" style="float:left; margin-left:15px; margin-top:5px;">
            <img src="style/default/printerLarge.png" alt="" />
        </div>

        <div id="pageTitleDiv" style="float:left">
            <span style="display:block; margin-top:20px;margin-left:10px;color:#78b4bb; font-size:20px;">Reports And Analyses</span>
            <span style="display:block; margin-top:20px;margin-left:10px;font-size:18px;">Select a report</span>   
        </div>

    </div>
    <br />
    <div id="mainPane" style="display:inline-block;width:100%;">
        <div id="readerTreeContainer" style="float:left;border-top-style:solid;border-left-style:solid;border-bottom-style:solid;border-right:none; border-width:1px; overflow : auto;width:300px;height:auto; background-color:white;">
             <vio:TreeView ID="TreeView" runat="server"
                     Width="298" Height="500"
                     ActionListener="ReportsGeneralListener"
                     ActionListenerScript="ReportsGeneralTree.js"
                     GlobalTreeviewName="reportsTreeview">
             </vio:TreeView>

        </div>

        <div id="FiltersContainer" style="position:relative;visibility:hidden;float:left;border-top-style:solid;border-right-style:solid;border-bottom-style:solid;border-left:solid 1px; border-width:2px; overflow : auto;width:30%;height:500px; background-color:#dbdae4;">
            <div id="filterColumnOne" style="float:left;width:50%;height:100%;border-right:solid 1px;border-left:none;">

            </div>
                <div id="filterColumnTwo" style="float:left;width:49%;height:100%;">
            </div>
            <div id="loadingDiv" style="z-index:10;position:absolute;top:50%;left:50%;margin: -35% 0 0 -35%;z-index:100001;height:316px;width:396px;">
                <div  style="position:relative;display:block">
                     <img src="style/default/loading.gif" alt="" style="position:absolute;left:0px;top:0px;z-index:-1;"/>
                    <span style="display:block;text-align:center;padding-top:80px;font-size:25px;font-weight:bold;">Loading Report</span>
               </div>
            </div>
        </div>

        <div id="ActionsContainer" style="visibility:hidden;float:left;border-left-style:none;border-top-style:solid;border-right-style:solid;border-bottom-style:solid;border-width:2px; overflow : auto;width:200px;height:200px; background-color:#abe9e7;">
              <div style="display:block;border-bottom:solid 1px;height:50%">
                  <div style="position:relative; height:100%;">
                      <div style="position:absolute;top:50%;left:50%; height:72px;margin: -35px 0 0 -35%;">
                          <img src="style/default/document.png" alt="" style="float:left;margin-right:10px;"/>
                          <button type="button" style="margin-top:18%;height:30px;" onclick="print();">Print</button>
                      </div>
                  </div>

              </div>

              <div style="display:block;border:none;height:49%;">
                  <div style="position:relative; height:100%;">
                      <div style="position:absolute;top:50%;left:50%; height:72px;margin: -35px 0 0 -35%;">
                          <img src="style/default/application_pdf.png" alt="" style="float:left;margin-right:10px;height:72px;"/>
                          <button type="button" style="margin-top:18%;height:30px;">PDF</button>
                      </div>
                  </div>
              </div>
        </div>

    </div>

Answer №1

You may want to consider using .hide and .show instead, as they are compatible with all browsers.

For more information, refer to the jQuery API documentation

It seems like the issue you were facing was:

<div that contains hidden content>
    <div for loading screen>

To see a successful demonstration of the provided solution, check out this link. I made some adjustments such as removing the inline visibility:hidden from the styles (I recommend moving it to a separate CSS file for better readability) and relocating the loading div outside of the hidden div.

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

positioning two out of three items in a navigation menu to the right and the remaining one to the left

I am looking to design a navigation bar that spans the full width of the screen, with the logo on the left side serving as a link back to the home page. Additionally, I want to include elements for register/login and cart. The background color should cove ...

AngularJS: handling multiple asynchronous requests

When I make multiple ajax calls in my code, I noticed that the API is only reached after all the ajax calls have been executed. Below you can see the JavaScript code: function test = function(){ var entity = {}; entity.Number = 1; ...

Looking to modify the height and width of an image when it is hovered over using inline CSS

My current project involves working with a dynamic template where the HTML code is generated from the back-end using TypeScript. I am trying to implement inline CSS on hover, but despite having written the necessary code, it does not seem to work as intend ...

The issue of changing the body font size in MUI v5 with React Styleguidist, ScopedCSSBaseline, and createTheme style overrides remains unresolved

Recently, I successfully migrated two MUI-powered UIs from MUI v4 to v5. In the process, I had to override their body fontSize according to the MUI migration guide to maintain the v4 design default of Typography body2 font size. This adjustment has worked ...

Tips for horizontally arranging a list with a flexible number of columns

I am attempting to create a horizontal list with 3 columns that automatically moves to a new line when the columns are filled. I have been trying to implement this using PHP but haven't had any success. If anyone could provide some guidance on how to ...

Adding Data Definition Language (DDL) statements while making an AJAX call

Is there a way to automatically update the value of a drop-down list whenever a partial view is loaded via an AJAX call? Currently, the AJAX call successfully retrieves the necessary information, but the user still needs to manually change the location val ...

Creating a JQuery statement to conditionally change CSS values

Is there a way to determine if a div element with a CSS class of "x" has a height set to "auto"? If so, I would like a jQuery script to remove the CSS class "a" from all elements with the class "y". If not, the script can remain unchanged. Thank you. ...

What is the best way to reduce the size of a Bootstrap card image back to its original dimensions when

I am currently experimenting with a bootstrap card using HTML, CSS, and Bootstrap. My main focus right now is on how to shrink the image when hovering over it. The .card-header-img has a fixed height of 150px that I do not want to modify. What I want to a ...

Creating a webpage that automatically clicks on a specific category from a selection using JavaScript and CSS

My latest project involves a page filled with divs, each containing specific text content. Located at the top of the page are buttons that enable filtering of the displayed divs based on their data-category. For instance, I have arranged divs showcasing al ...

What are the steps to achieve such a design?

Can you show me how to create a single layout using HTML and CSS? I am struggling with splitting the screen properly. Could you provide a simple example, maybe on jsfiddle? https://i.stack.imgur.com/d2rbn.jpg Thank you in advance! EDIT: I have added a ...

The PHP Include function seems to be malfunctioning and unable to properly display

Everything you see is what I have on my home.php page <?php include ('../bgs/bg-verbier.html'); include('../menus/menu-verbier.html'); ?> Both of the files requested are located in the parent directory. The /menus/menu-v ...

Arrange the div next to each other

Looking to position two divs side by side with widths totaling 100%? The left div will have a specified width in pixels that can change, while the right div should expand to fill the remaining space. Having trouble with this layout? Check out my example o ...

Create a hover effect on HTML map area using CSS

Is it possible to change the background color of an image map area on hover and click without using any third-party plugins? I attempted the following code: $(document).on('click', '.states', function(){ $(this).css("backgro ...

Inquiries regarding real-time alerts and notifications

Just curious, I am wondering about the creation of those notifications/alerts (for example on platforms like twitchalerts, commonly used by livestreamers). Are they typically coded in JavaScript/AJAX or another language? Is there a specific framework for ...

At what point does IE7 recalculate styles? It seems to have difficulty functioning consistently when a class is applied to the body

Currently facing a peculiar issue. I'm utilizing a class on the element as a toggle switch to control various layout behaviors on my website. When the class is active, specific actions occur; when it's inactive, these actions do not take place. ...

Creating a NgFor loop in Angular 8 to display a dropdown menu styled using Material

I'm currently facing an issue with incorporating a Materialize dropdown within a dynamically generated table using *ngFor. The dropdown does not display when placed inside the table, however, it works perfectly fine when placed outside. <p>User ...

Modify the color or background color of a disabled Material UI checkbox

The disabled unchecked checkbox appears too subtle to me, and I would like to enhance it by giving it a grey background and changing the cursor style to not-allowed. I've been trying to implement these styles on the checkbox using the makeStyles, but ...

Load jQuery in PHP script and return it

After searching around, I have not been able to find a suitable example for what I am trying to accomplish. Here is the scenario that I am facing: On a page (constructed in PHP and HTML), there is an included PHP script (currentMonth.php) that runs when th ...

I am encountering a 404 error when attempting to make a GET request for a file located in the same directory

Here is the Javascript code that utilizes the get method. The directory contains both files - the HTML file where the JS code resides, and the text file. Below is an image of the console displaying errors. ...

The GWT plugin seems to be missing when using chromedriver

Trying to run Selenium tests on a GWT Java application and utilizing the ChromeDriver for this purpose. Requiring the GWT Plugin in the settings, here's the process I follow: @Provides @Singleton protected WebDriver getDefaultWebDriver() throws IOEx ...