What could be causing my CSS/Layout to alter once AJAX/JavaScript has been executed?

When the user clicks, an AJAX call is made to retrieve data from a third-party API. The frontend/layout renders correctly before this action; however, after the data is fetched and displayed in the frontend, the layout changes.

Upon debugging multiple times, it appears that the inherited relation is being altered.

What could be causing this issue?

This section of HTML is affected:

#mainContent .fourthRow .Goals {
  float: left;
  width: 20%;
  height: 280px;
  margin-right: 5px;
  background-color: #F2F8FF;
}

#mainContent .fourthRow .goalsColumn {
  background-color: #F2F8FF;
  display: inline-block;
  float: left;
  height: 100%;
  width: 24.3%;
  text-align: center;
  border-right: 1px solid;
  margin-right: 1px;
  border-color: #DADADA;
  font-family: 'Muli', sans-serif;
  font-weight: bold;
  font-size: 15px;
}

#mainContent .fourthRow .goalsColumn p {
  height: 40px;
  border-bottom: 1px solid;
  border-color: #DADADA;
  font-family: 'Muli', sans-serif;
  vertical-align: middle;
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
}
<div class="fourthRow">
    <div class="Goals">
      <div class="goalsColumn">
        <div id="divGoal"><img id="goal" src="{% static "images/goal.png" %}" alt="soccergoal"></div>
        <div><p>Scored Goals</p></div>
        <div><p>SGPM</p></div>
        <div><p>Conceded Goals</p></div>
        <div><p>CGPM</p></div>
        <div><p>Goals Total</p></div>
        <div><p>GTPM</p></div>
      </div>
      <div class="goalsColumn">
        <div><p>Home</p></div>
        <div id="goals_home_for" "goals_style"><p></p></div>
        <div id="goalsAvg_home_for"><p></p></div>
        <div id="goals_home_against"><p></p></div>
        <div id="goalsAvg_home_against"><p></p></div>
        <div id="goals_total_home"><p></p></div>
        <div id="goalsAvg_home_total"><p></p></div>
      </div>
      <div class="goalsColumn">
        <div><p>Away</p></div>
        <div id="goals_away_for"><p></p></div>
        <div id="goalsAvg_away_for"><p></p></div>
        <div id="goals_away_against"><p></p></div>
        <div id="goalsAvg_away_against"><p></p></div>
        <div id="goals_total_away"><p></p></div>
        <div id="goalsAvg_away_total"><p></p></div>
      </div>
      <div class="goalsColumn">
        <div><p>Total</p></div>
        <div id="goals_total_for2"><p></p></div>
        <div id="goalsAvg_total_for"><p></p></div>
        <div id="goals_total_against"><p></p></div>
        <div id="goalsAvg_total_against"><p></p></div>
        <div id="goals_total"><p></p></div>
        <div id="goalsAvg_total"><p></p></div>
      </div>
    </div;

Display Before JS/AJAX Call:

https://i.sstatic.net/2dRip.jpg

Layout After JS/AJAX Call:

https://i.sstatic.net/pPoHj.jpg

Answer №1

When making an ajax request, the div#goals_home_for element initially contains a p tag with a style of height: 40px, giving the div a height of 40px. However, if the ajax response includes JSON data that alters the DOM and removes the child p tag from div#goals_home_for, the div will lose its height. In summary, consider using the CSS:

#mainContent .fourthRow #goals_home_for {
   height: 40px;
   <!-- Rest is omitted -->
}

Alternatively, adjust your javascript to ensure that each data item is wrapped in a p tag.

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

AngularJS encounters failure during shared data service initialization

As a newcomer to AngularJS, I aim to develop an application in adherence to John Papa's AngularJS style guide. To familiarize myself with these best practices, I have opted for the HotTowel skeleton. My application requires consuming an HTTP API endp ...

javascript onload button is selected

I am looking to create a button on page load for my login page in Chrome. I want the login button to be preselected when the page loads, and when I press Enter, the onclick function of the button should be triggered. Any advice on how to achieve this? Th ...

Semi-transparent image

Can I achieve a semi-transparent image? Similar to this gradient: background:linear-gradient(to bottom,rgb(44, 44, 44),rgb(29, 38, 51,0.322)); ...

Updating new objects in Angular using JavaScript Object-Oriented Programming may not be working

Recently delving into OOP in JavaScript while working on an AngularJS website, I encountered a situation where my object methods were only altering the properties within the class, but not affecting the new object itself. //Class Var Item = function() { ...

Issue with mobile.changePage() function not executing as expected

I created a basic code that generates a "Splash screen". For storing my data, I am utilizing localstorage. When I first load it, I retrieve data from a URL and I am able to navigate to different pages using $.mobile.changePage(). However, if the data is a ...

Arrange JSON information in an HTML table with distinct header rows for every data category

I have a JSON object with a key:value pair named callRoot. Some examples of values for this pair are @S, @C, and @W. There are multiple objects that share the same value and I want to create an HTML table head row at the beginning of each group and repeat ...

Is it possible to access a PHP variable from a different file in an HTML file?

Can someone help me with separating the javascript from this php file? I need to specify where the javascript should look for the php file, as currently it only executes within the php file. <?php date_default_timezone_set('Europe/London'); r ...

"Securing Your Web Application with Customized HTTP Headers

I'm currently working on setting up a POST request to a REST API (Cloudsight) with basic authorization. Here is the code I have so far: var xhr = new XMLHttpRequest(); xhr.open("POST", "http://api.cloudsightapi.com/image_requests", true); xhr.setRequ ...

Error 400: Token Obtain Pair request failed in Django REST with simpleJWT and Vue 3 composition API

I'm encountering an issue with obtaining the refresh and access tokens when sending a form from my Vue app to the Django REST API. CORS has been enabled, and signing up through the REST API page or using Postman doesn't pose any problems. However ...

Challenges with fading images using jQuery

I am currently working on animating a 5 image slideshow by creating a fading effect between the images rather than just switching abruptly. Here is my HTML structure: <div id="slides"> <ul class="pics"> <li><img src="imag ...

AngularJS: default option not being selected in dropdown menus

I need assistance with a dropdown list issue. See the code snippet below: My Controller (function(angular) { 'use strict'; angular.module('ngrepeatSelect', []) .controller('ExampleController', ['$scope', functi ...

The error message "Blazor WebAssembly JSRuntime.InvokeVoidAsync - blazor.webassembly.js:1 Uncaught (in promise) TypeError: Converting circular structure to JSON" indicates that

I have implemented the drawio-integration project in my Blazor WebAssembly application. https://github.com/jgraph/drawio-integration This is how the simple helloworld sample appears: <img onclick='DiagramEditor.editElement(this);' src=" ...

The web typography appears fuzzy or has incorrect thickness, lacks consistency across pages and even within a single page

The font (ProggyCleanSZBP.ttf from 1.1.5 release) appears to be intermittently thick and blurry. If you compare with , you'll notice that the latter displays as desired in most cases, but there are instances where the issue occurs, such as the first ...

Hyperlinking Github.io Images

I'm facing an issue regarding image paths on github.io. It seems like the images from my github repository are not displaying properly (I made sure to check spelling and case sensitivity). I'm running out of ideas, so maybe you can help me spot m ...

What is causing the list-sorter to malfunction?

This website crashes when executed: <head> <script> var numbersList = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]; var orderedList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, ...

Applying FadeIn Effect to Background Image on Hover

For several applications, I have utilized this jQuery code that swaps images with a smooth fading effect. It's incredibly straightforward. $(document).ready(function() { $("img.a").hover( function() { $(this).stop().animate({ ...

Utilizing the "return" keyword in Javascript outside of function declarations

Exploring the Impact of Using the Return Keyword in JavaScript Scripts Beyond Functions in Browsers and Node.js Recently, I experimented with utilizing the return keyword in a Node.js script like so: #!/usr/bin/env node return 10; My initial assumption ...

Sharing a boolean state between two pages using Material UI components

One challenge I've been facing is passing a boolean useState value between two pages. I found a helpful solution on this Stack Overflow thread: How to call useState from another Page? The main goal here is to display a success alert on a separate pag ...

Tips for transferring the value of ng-model to multiple controllers

Is it possible to access the value of an ng-model from two different controllers? While I am aware that using a service is one way to share data between controllers, I am struggling to figure out how to pass the value of an ng-model to a service for this ...

Include a Vue component within another Vue component in a Laravel application using VueJs

I've recently integrated Vue.js into my Laravel project and encountered an issue when trying to call a component within another component. After running the command npm run dev, I received a webpack error. Here is the code snippet from my parent comp ...