Loading jQuery leads to the entire body of the webpage becoming white

As I transition from a welcoming page to a new content page using jQuery's fadeOut/fadeIn and load functions, I encounter an issue where the background, which is black on both pages, suddenly changes to white upon loading the second page.

This isn't just a quick 'white flash' but rather a permanent switch to a white background. Can anyone shed light on why this might be happening or point out any mistakes I may have made? It feels like I must have missed something fundamental.

index.html:

<!DOCTYPE html>
  <head>
    <link rel="stylesheet" type="text/css" href="css/style.css" />
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
    <script type="text/javascript">
      $(document).ready(function() {
        $(function(){
            $('#go').click(function() {
                $('html').fadeOut(2500, function() {
                    $(this).load('second.html', function() {
                        $(this).fadeIn(2500);
                    });
                });
                return false;
            });
        })
      });
    </script>
  </head>
  <body>
      <a id="go">Go!</a>
  </body>
</html>

second.html:

<!DOCTYPE html>
  <head>
    <link rel="stylesheet" type="text/css" href="css/style.css" />
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
  </head>
  <body>&nbsp;</body>
</html>

style.css:

body {
  background: #000000;
}

Answer №1

evaluation...

$('#start').click(function() { // when start button is clicked...
      $('body').fadeOut(2500, function() { // body fades out....
           $(this).load('next.html', function() { // body content updates...
                $(this).fadeIn(2500); // this part will not execute... as the entire body content changes... including the <head> which contains the script... saying goodbye to this line...
           });
      });
      return false;
});

recommendation, modify only the <body> section...

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

What is the best way to generate an image from HTML code?

When I send emails with the HTML created, the design changes when viewed in Outlook. To address this issue, I am attempting to convert the HTML source into an image before sending the email. To do this, I have stored the HTML source in a string variable l ...

In NextJs version 13, you can access parameters from the URL directly within the layout.js file

With the introduction of server components in Next.js 13, accessing parameters from the URL has become seamless. Let's look at an example: app/shop/[tag]/[item]/layout.js /shop/1/2 { tag: '1', item: '2' } When accessing page ...

Navigating the website with curtain.js and anchor tags

Currently, I am working on a website located at www.TheOneCraft.co.uk. I have incorporated the curtain.js jQuery plugin to create animated slide/pages as users scroll down. However, I have been unsuccessful in making the navigation bar follow this animati ...

Interconnected dropdown selections for multiple dropdown menus

I have successfully implemented a jQuery function that populates the second dropdown options based on the selection of the first dropdown option. However, I am facing an issue with having multiple instances of this functionality in rows. When I change the ...

JQuery hover effect causes mouse pointer to flicker

I'm currently working on creating a mega menu using Bootstrap 4, and I came across this code: While the code works well, I wanted to add a slide down/slide up effect to reveal the dropdown content when hovering over the dropdown link. So, I included ...

Add the information from the tag to the retrieval query path

How can I extract the information from this paragraph: <p id1="p-1-1"> Samsung Galaxy S8 Dual </ p> and insert it into this parameter: <a href="/about?param=HERE" class="btn2"> Learn more </a> The text within the p tag may chan ...

Setting up protected routes using react-router-dom version 6

When a visitor navigates to / (home), I want them to be redirected to /connexion" if they are not connected. To achieve this, I have implemented Private routes that work well. Now, I need to create the logic that will handle the redirection based on t ...

Unshrinkable item causing multiple lines text-overflow in a flexbox layout

My goal is to achieve the following design: https://i.stack.imgur.com/YLUtN.png Currently, I have attempted the following approach (although it doesn't fully meet my requirements): .parent { max-height: 40px; display: flex; flex-wrap: wrap; ...

The onRendered function fails to load all data in the template

I'm dealing with a frustrating bug that I just can't seem to fix. I've been attempting to load all users using Users.find() into one of my layout sub-templates, but for some reason, it's not working as expected. Instead of loading all u ...

Spinning a line in three.js along the circumference of a circle

let lineGeo = new THREE.Geometry(); let lineMat = new THREE.LineBasicMaterial({ color: 0x000000 }); lineGeo.vertices.push( new THREE.Vector3(0, 0, 0), new THREE.Vector3(0, 10, 0), ); let myLine = new THREE.Line(lineGeo, lineMat); scene.add(myLi ...

Retrieve documents from mongodb that were created in the past half hour

Currently, I am in Central European Summer Time (CEST) and at 15:08, I added a document to my collection. When passing timestamps: true to a new Schema, the createdAt time is showing two hours too early: createdAt:2019-08-21 13:08:39.219 Why is this happ ...

What steps can I take to resolve the issue of the Error value not being iterable?

I encountered an issue in my table where I get the error message value is not iterable when there is no value to iterate through. How can I handle this error in my code? Snippet of Code: if (null != data && data) { data = data.map((item) => ...

You've got a function floating around without any specific theme tied to it. Make sure one of the parent elements is utilizing a ThemeProvider for proper context

I am working on implementing a Navbar in my current Project. The dependencies I am using are: mui/icons-material: ^5.2.5 mui/material: ^5.2.6 mui/styles: ^5.2.3 Here is the folder structure of my project: Root.jsx Navbar.jsx styles ...

Exploring the world of AJAX: My initial roadblock

Referring to http://jsfiddle.net/DLy6j/ var echoHTML = '<img src="URL-TO-MY-IMAGE.JPG"/>'; $.ajax({ type: 'post', url: '/echo/html/', data: { html: echoHTML, delay: 2 }, beforeSend: ...

What is the best way to incorporate JQuery into html content retrieved through an ajax request?

In my jsp file, there is a div structured like this : <div id="response" class="response"></div> After triggering an ajax call to a servlet, the content of this div gets updated with the following elements : <div id="response" class="res ...

utilizing the JavaScript SDK to send alerts to a user's friends on Facebook

I am attempting to send a notification to a user's friend using the JS SDK on a Facebook canvas app, but I'm encountering this error in the console: POST https://graph.facebook.com/16542203957691/notifications? 400 (OK) jquery.min.js:140 c.exten ...

Incorporate an array in PHP and employ jQuery's 'get' method

I am attempting to query the database in PHP and retrieve a "toplist" that is limited to 10 results. My goal is to create an array and send it back to Jquery using $.get(). However, I am facing issues with receiving all the data with this code. How can I ...

Tips for replacing all occurrences of a specific string in HTML while preserving JavaScript attributes

Is there a way to use RegEx to replace part of an HTML document without affecting the root element or other elements like event listeners? Consider this scenario: for (; document.body.innerHTML.indexOf(/ea/) != -1;) { document.body.innerHTML = docu ...

Is there a way to convert a URL into a clickable link and retrieve the YouTube code embedded within

I have retrieved a string from the database using PHP and I want to echo it. Within this string, there is a YouTube link that I would like to make clickable, as well as extract the YouTube code at the end of the link. How can I achieve this? For example: ...

Turn off jQuery.validate's client-side refresh

I recently implemented the jQuery.validate plugin for client-side form validation, utilizing an error summary panel instead of displaying individual error messages for each field. The plugin has been working flawlessly, but I've received a somewhat un ...