A fleeting moment reveals a broken image tag

How can I prevent the broken image tag from briefly appearing when the page loads?

Take a look at this example: http://jsfiddle.net/v8DLe/196/

I have already implemented:

onerror="this.style.display ='none'"

Is there a way to still use the img tag and avoid using a div with style={{ backgroundImage: ...}} instead?

Answer №1

Initially, conceal them. Reveal them only when the onLoad event is triggered.

img {
  display: none;
    width:200px;
    height:200px;
}
<img src="abc" alt=" " onload="this.style.display ='block'"/>
<img src="abc" alt=" " onload="this.style.display ='block'"/>
<img src="https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" alt=" " onload="this.style.display ='block'"/>
<img src="abc" alt=" " onload="this.style.display ='block'"/>
<img src="abc" alt=" " onload="this.style.display ='block'"/>
<img src="abc" alt=" " onload="this.style.display ='block'"/>

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

When using Selenium to locate a sub element within a previously obtained WebElement using xpath, it will always return the first match found on the entire

Currently, my project involves using selenium and python to automate website testing. I am facing an issue while trying to extract links to files on the website using the following approach: I first use divs = find_elements_by_css_selector("div.answer") to ...

- Aligning list items using UL bullet style

I'm having trouble aligning my ul dropdown with the rest of my menu. Even after removing the Bullet from my ul dropdown, it still maintains its position (I expected it to move all the way to the left side of the page). I've attempted various st ...

The subfolder and HTML page have identical names and are not functioning properly

I recently updated my webpage by removing the .html extensions using htaccess. My website includes a page named "blog.html" and a subfolder called "blog" with additional html pages inside. RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ ...

Is it possible to upload an image through AJAX/jQuery without relying on Flash or iframes?

Furthermore, I am keen on minimizing the use of plugins, with the exception of jQuery. I already have a complex system in place and I prefer not to burden it with an abundance of plugins. If absolutely necessary, I will opt for something that is extremel ...

What is the best way to align the width of an HTML header with its text content?

Here's a question that might seem pretty straightforward: I've got different HTML headers with colored backgrounds. The issue I'm running into is that without setting a specific width, they always end up taking the full width of the contai ...

Having trouble uploading an image in a React application with the error message "Token is invalid or unexpected"?

Encountering an error while running my Node/React app has me puzzled. Previously, I had no trouble importing images using create-react-app. However, now I am attempting server-side rendering following a pluralsight course on configuring webpack and babel m ...

Creating dynamic images with animated text using PHP

How can I add a personal touch to my website banners for visitors? 1) Currently, only the first frame of GIF images is being displayed in the animated banners 2) I am looking to incorporate a text field where users can input their desired text. Upon form ...

Activate navigation state dynamically

Having encountered this issue repeatedly, I struggle to find a solution. My Wordpress site features a top navigation located in my header.php file and used across all pages, making it impossible to hardcode the active menu state for each individual page. ...

Struggling to successfully deploy a React App to Azure through a Github Actions workflow due to encountering a TypeScript error

I have been searching extensively on SO for the past few days, trying different methods but I just can't seem to make this work. This is not my usual area of expertise as I am a .Net developer and I inherited this project. To get where I am now, I fo ...

What is the correct way to remove listeners in componentWillUnmount using React, and why is binding necessary in the constructor?

I'm feeling a bit perplexed, can someone explain the distinction between these two snippets of code: constructor(props) { super(props); this.state = { openPane: false } this.togglePaneHelper = this.togglePaneHelper.bind(this); ...

How to retrieve the dimensions of an image for a specified CSS class with Selenium or PIL in Python

I am interested in using Python to determine the size of specific images. Is it possible to automate this process so that I can identify only images with certain classes? I am unfamiliar with PIL. Could I define the CSS class/name/id after specifying the U ...

Strange outcomes observed with array created from HTML code

html : <input type="text" name="ps[part1['test']]" value="testing multiple array"> Current result : [ps] => Array ( [part1['test'] => testing multiple array ) Expecting result : [ps] => Array ( ...

"Troubleshooting: Difficulty with hover function in jqgrid not functioning on colored rows

My JQGrid setup includes the following: <table id="grid"></table> var data = [[48803, "DSK1", "", "02200220", "OPEN"], [48769, "APPR", "", "77733337", "ENTERED"]]; $("#grid").jqGrid({ datatype: "local", height: 250, colNa ...

Once the image is requested in HTML, three.js makes a subsequent request for the same image

This is a block of code. let image = new THREE.TextureLoader().load("http://odf9m3avc.bkt.clouddn.com/1493817789932.jpg") <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/88/three.min.js"></script> <img class='preLoad&apo ...

Retrieve the value of a style property using the css() method

<p class="pen" style="color:#000">abc</p> .pen{ color:#333 } In the previous code snippet, we have an HTML element with inline style and a CSS class that defines color properties. Despite the inline style having higher precedence, jQuery retu ...

Sorting through various data inputs in one JSON file

I have a JSON file containing an array of objects: obj= [{fname:"abhi",age:5,class:"ten",lanme:"kumar" },{fname:"abhi",age:5,class:"ten",lanme:"kumar" },{fname:"abhi",age:5,class:"t ...

CSS: Floating navigation bar that becomes fixed upon reaching the top of the page

Looking for a creative approach to achieve the following: An innovative navigation bar that initially appears on a page regularly but then becomes fixed at the top as I scroll down. An alternative perspective: imagine a navigation bar that starts off unf ...

What is the best way to notify the user if the percentage entered is not a numeric value?

My role is to notify the user when the entered value exceeds the acceptable range: if (document.myForm.outputPercentage.value <= 0 || document.myForm.outputPercentage.value >= 100) { alert( "Please enter a percentage between 1 and 100 ...

The jsonGenerator is unable to process strings containing spaces

Hey, I'm having trouble passing a string with whitespaces to my JavaScript function using jsonGenerator. Here's the code snippet: jGenerator.writeStringField(cols[8], ap.getContentId() != null ? "<img src='img/active.png' onclick=au ...

ReactJS allows for the use of immutable values while still being able to

In my current project, I have predefined values for yearOfEnforcementProceesdings + cityOfEnforcementProceedings. Additionally, there is a serialNumber input field that requires user input. The goal is to display two more unaltered values whenever the seri ...