Hiding content by using "display: none" in CSS. How much does

I came up with a solution to create a "read more..." function using two div elements, and hiding one of them with display: none. The only downside is that it doubles the data storage. Now, here's my question:


If I have just one div element with style="display:none", containing multiple large images, will this affect the loading time of the page?

Answer №1

display:none doesn't stop the hidden content from loading along with the rest of the page.

To reduce the load time of the page, consider using Ajax to load the "read more.." content only when it is requested.

Answer №2

Even if the parent div is hidden with display: none, the images can still be fetched immediately.

If you don't want this behavior and prefer not to use AJAX, one option is to insert the images into the DOM only when the user clicks on a "read more..." button, like in the code snippet below:

var hiddenContainer = document.getElementById("your-hidden-container-id");
var newImage = document.createElement("img");

newImage.setAttribute("src", "image2.png");

hiddenContainer.appendChild(newImage);

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

Eliminating bottom section in HTML/CSS

I've got this code snippet: new WOW().init(); /* AUTHOR LINK */ $('.about-me-img img, .authorWindowWrapper').hover(function() { $('.authorWindowWrapper').stop().fadeIn('fast').find('p').addClass('tr ...

``How can I prevent browser popups/tooltips from appearing when a user exceeds the maximum value in a number

Is there a way to prevent the tooltip from appearing on the image when a user manually enters a quantity that exceeds the maximum allowed? The tooltip pops up when the form is submitted, and I need to find a way to turn it off. It seems like this tooltip ...

Issue encountered: Compilation error occurred following the update from Angular 11 to Angular 15, stemming from the module build failure within the sass-loader directory

I recently attempted to update angular from version 11 to 15, but encountered an error as shown in the screenshot below ./src/assets/styles.scss - Error: Module build failed (from ./node_modules/sass-loader/dist/cjs.js): SassError: expected "(". ...

Is there a way to substitute all underscores in HTML tag IDs and classes with a hyphen symbol?

I recently realized that I used underscores instead of hyphens in some of my CSS class and id names. To correct this, I want to replace all underscores with hyphens using the sublime text replace feature (ctrl + H). Is there a way to change underscores to ...

Is there a way to modify a scope variable using the on-scroll event in an Ionic app?

I am trying to update a variable's value when the scroll position exceeds 100 from the top, but for some reason it is not working as expected. The value of the variable does not change in $scope. Here is the code snippet: <div ng-show="title===tr ...

Using the absolute positioning property in CSS is causing the text box to move downwards

I created a prototype using material-UI chips. Upon clicking the Test IPA, the textbox should appear right below the text Test IPA. In the prototype, it does show up below the text but when I include other functionalities, it ends up at the bottom instea ...

Display the content as a clickable link using Jquery

Here is the view I have created using .NET MVC3: function DisplayingGrid () { var Geo=$('#ddlGeo').val(); var Vertical=$('#ddlVertical').val(); var Month=$('#ddlMonth').val(); if(Vertical=="All") { var Flag=1; ...

What happens when dynamically loaded static resources are loaded?

Currently, I am dynamically injecting HTML into a page using JQuery AJAX. The injected HTML contains script and link tags for JS and CSS files respectively. The issue I am facing is that my initPage() function runs before the script containing its definiti ...

Angular - Dividing Values within Input Arrays

In the input field available to users, they can enter multiple inputs separated by commas. <div class="container"> Enter your values:<input type="text" multiple #inputCheck> <input type="submit"(cli ...

How can Selenium and Python be used to refresh a webpage until a specific item is found?

I'm attempting to continuously refresh the page until a specific item appears, but my current code is not working. I took inspiration from this solution: python selenium keep refreshing until item found (Chromedriver). Below is my code snippet: whil ...

The dropdown feature in Bootstrap 5 seems to be malfunctioning in Angular 12

I am facing issues while trying to implement the Bootstrap 5 dropdown in Angular 12. After installing all required packages and adding them to the angular.json file, I still cannot get it to work properly. Even after copying the example directly from the ...

What is the best way to show an on/off button in an HTML page when it loads, based on a value stored in a MySQL database?

Is there a way to display a toggle button onload based on a value from a MySQL database table? I need the button to switch between 0 and 1 when clicked. I've looked at several solutions but none of them seem to work for me. Any help would be greatly a ...

When files are uploaded to the server, the hyperlinks fail to function properly

I am currently facing an issue with the admin side panel dropdown links on a project I am working on. The admin panel includes both regular links and dropdown elements. While the single links are functioning properly, the dropdown is not opening to displ ...

Unable to properly receive email address and attachment in PHPMailer

I am facing an issue with sending emails with attachments using PHP. The problem I encounter is that the email address and attachment are not being properly received in my code. While manually providing the email address results in successful email sending ...

Submitting an HTML form twice simultaneously without causing any interference

I am seeking a way to submit an HTML form in two different ways. First, I want to use jQuery's .submit() function to send the information to a webservice. After that, I need to also send the form data to my database. The issue arises when I use even ...

Accessing JavaScript cookie within .htaccess file to establish redirection parameters according to cookie content

Is there a way to modify the rules within my .htaccess file so that it can properly read a user-side cookie and redirect based on its content? The scenario is this: I have a cookie called userstate which contains an abbreviation of US states, such as AL ( ...

Change the background color of a Bootstrap dropdown when toggled

I recently created this code snippet: <div class="dropdown"> <button class="btn btn-secondary dropdown-toggle buttonForProfile" type="button" id="dropdownMenuButton" data-bs-toggle='dropdo ...

Incorporate the stylish PayPal icon from Font Awesome into the PayPal code

I'm experimenting with adding the font awesome paypal icon <i class="fa fa-paypal" ></i> before the PAY WITH PAYPAL text on my button. You can see a similar setup on this page with the shopping cart icon <i class="fa fa-shopping-cart"& ...

Who is responsible for triggering a PostBack?

I am trying to identify the control that triggers a page PostBack within the Page_Load event, as there are multiple controls on my page. ...

Guide to dynamically loading customer data into an HTML table using JavaScript

I'm looking to populate a table with data on customers including their name, customer ID, and rental cost. Can anyone help me with the JavaScript code needed to insert this data into rows of the table? Your assistance is greatly appreciated. Below is ...