Hiding the div element with 'display: none' causes the disappearance

Whenever I execute this piece of code;

document.getElementById("loading").style.display = "none"

It unexpectedly hides the div named "myDiv" as well.

By setting MyDiv to block, the text appears correctly. However, when loading is set to none, it strangely removes MyDiv too. What I actually want is for it to only hide the display div.

<head>
<style>
 .loading {
     position: absolute;
     left: 50%;
     top: 50%;
     margin: -60px 0 0 -60px;
     background: #fff;
     width: 100px;
     height: 100px;
     border-radius: 100%;
     border: 10px solid #19bee1;
 }
 .loading:after {
     content: '';
     background: trasparent;
     width: 140%;
     height: 140%;
     position: absolute;
     border-radius: 100%;
     top: -20%;
     left: -20%;
     opacity: 0.7;
     box-shadow: rgba(0, 163, 204, 0.6) -4px -5px 3px -3px;
     animation: rotate 2s infinite linear;
 }
 @keyframes rotate {
     0% {
         transform: rotateZ(0deg);
     }
     100% {
         transform: rotateZ(360deg);
     }
 }
    </style>
</head>

<div class="loading" id="loading"</div>

<body onload="myFunction()">

<div class="myDiv" id="myDiv" style="display:none;" >
  <h2>Tada!</h2>
  <p>Some text in my newly loaded page..</p>
</div>

<script>
var myVar;
var toooa
function myFunction() {
    myVar = setTimeout(showPage, 3000);
}

function showPage() {

  document.getElementById("myDiv").style.display = "block"
  document.getElementById("loading").style.display = "none"
}
</script>

</body>
</html>

http://codepen.io/anon/pen/QGdYdw?editors=1000#0

Answer №1

Your code has an issue that may cause unexpected behavior:

<section class="wrapper" id="wrapper"</section>

The correct format is:

<section class="wrapper" id="wrapper"></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

Guidance on utilizing jQuery to display values depending on a dropdown selection

This code snippet displays movie data from a JSON variable in a dropdown list based on the selected city. It also needs to show the movie name and theaters list when a user selects a movie, along with the theater dropdown remaining unchanged. Here is my H ...

The Add and Update functions of an AngularJS application are malfunctioning in Internet Explorer

Encountered a situation where updates and additions in IE show results in Chrome :D // Extract category object and id from the parent $scope.addNewCategory = function (category, parentId) { $scope.resetError(); category.parentId = par ...

Perform PHP function without refreshing the page when clicking

I have a PHP script that displays an alert box with the options OK or CANCEL. If OK is clicked, it redirects to a link that triggers a PHP function to delete the selected image. <?php //echo $pictures['binId']; if(count($other_images)) { ...

Exploring the world of promise testing with Jasmine Node for Javascript

I am exploring promises testing with jasmine node. Despite my test running, it indicates that there are no assertions. I have included my code below - can anyone spot the issue? The 'then' part of the code is functioning correctly, as evidenced b ...

How can I personalize the preview feature in a Bootstrap rich text editor?

Currently, I am utilizing Bootstrap's rich text editor by this method $('#editor').wysiwyg();. Utilizing AJAX, I am passing the HTML content created by .wysiwyg to save it in the database. Later on, I plan to retrieve the saved HTML data to ...

why isn't bootstrap 4 pull-xs-right functioning properly?

I am utilizing Bootstrap 4 utilities to align buttons to the right of the screen in my HTML, and it is achieving the desired effect. However, I am facing an issue where the buttons are not pushing down the content below them as anticipated. Instead, they ...

Upgrading an Express 2.x application to Express 3.0

I am currently studying NodeJs and Express and am in the process of converting a tutorial app from Express 2.5.9 to version 3.0. The following code is now causing an error "500 Error: Failed to lookup view "views/login". How can I update this to render cor ...

Can Vue.js automatically refresh the display when there are changes in a third-party JSON file?

I'm attempting to achieve a specific goal using Vue, but I'm uncertain if it's feasible given my current struggles in obtaining the desired outcome: An API endpoint returns an array containing multiple objects. While I am able to successfu ...

problems with my ajax or jquery in codeigniter

Hey guys, I have successfully implemented the image edit update feature. However, I am facing an issue with the ajax call when I try to delete an image by clicking on the edit button. It gives me an error that I can't seem to figure out. Can anyone he ...

Tailoring information to fit selected preferences

Currently working on developing a fitness app with Vue, aiming to create personalized workout routines based on user preferences. Users can choose specific options and generate a workout plan by clicking a button. The collected data is stored as an object ...

The React Material Component stubbornly resists being horizontally aligned in the Code Sandbox

Currently, I am working on getting my Material design to function properly within the CodeSandbox environment. One issue I am encountering is attempting to center it horizontally. As of now, it appears like this: https://i.sstatic.net/ZK02y.png To make ...

Determine the specific button that was clicked within a React component

I have a challenge with dynamically generated material UI buttons. I am trying to identify which button was clicked by obtaining the value of the name attribute that I assigned to each button. Is there a way to accomplish this? In essence, I need to retrie ...

Looking to retrieve object values in JavaScript in a dynamic manner?

Imagine having an array of objects with nested objects. The data is always changing, meaning the keys may vary each time. For instance: [ { "uuid": "53e7202c-28c8-4083-b910-a92c946a7626", "extraIdentifiers": { "National ID": "NAT2804" }, ...

Ways to manage properties that are non-existent

Whenever vm8 encounters a property that doesn't exist, it will display an error message like this: Cannot read property 'value' of null. For example, when passing an id that doesn't exist: var pass = document.getElementById('pass ...

Encountering difficulties accessing XML file on server via anchor tag

I have an XML file on the server that I am attempting to open in a browser when the user clicks on a link. Below is how I have set up the link, but it is not opening the file: Code: <a title="View XML" href="file://///90.0.0.15/docmgmtandpub/PublishD ...

Strategies for adjusting image components based on various screen sizes

Let's consider a scenario: There is an image nested inside an introductory div for the desktop layout, like so: <div class="intro"> <img id="gambar" src="assets/images/image-intro-desktop.jpg" alt=&q ...

The onClick function within the .map function is continuously triggered

I am encountering an issue with my code where a Dialog confirmation prompt from Material UI keeps getting called unexpectedly. The problem seems to arise when I add a value to the function that is triggered by a button click within a loop of an array usi ...

Does PDO determine the status code for the server?

I have encountered a challenge while working on an ajax query within our framework. My issue is related to setting the server response code only at the point where the PDO execute method is invoked. The process follows this pattern: When an ajax query is ...

New data row successfully added to HTML table, revealing an object display

When I click a button, a dialog box opens up. I can fill out the form inside the dialog box and submit it to insert a row into a table. After submitting the form, the newly inserted row displays as [object Object] immediately after submission: https://i.s ...

How can we dynamically render a component in React using an object?

Hey everyone, I'm facing an issue. I would like to render a list that includes a title and an icon, and I want to do it dynamically using the map method. Here is the object from the backend API (there are more than 2 :D) // icons are Material UI Ic ...