Question:

Which of the following event will occur when loading of image is cancelled in JavaScript?

Show Hint

The abort event occurs when the loading of a media resource such as an image or video is interrupted before completion.
  • change
  • abort
  • error
  • reset
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is B

Solution and Explanation

Step 1: Understand JavaScript events.

JavaScript events are actions or occurrences that happen in the browser and can be detected by JavaScript code. Examples of events include clicking a button, loading a webpage, submitting a form, or cancelling a resource while it is loading.

These events allow developers to execute specific code when certain actions take place.

Step 2: Explain the abort event.

The abort event occurs when the loading of a resource such as an image, audio file, or video file is intentionally stopped before it finishes loading.

For example, if a browser begins loading an image but the user stops the loading process or navigates away from the page, the abort event is triggered.

Example:

<img src="image.jpg" onabort="alert('Image loading cancelled');">
In this case, if the image loading is cancelled, the abort event is activated.

Step 3: Analyze other options.

change: Triggered when the value of an input element changes.

error: Triggered when an error occurs during loading, such as a missing file.

reset: Occurs when a form reset button is clicked.

Step 4: Conclusion.

Therefore, when the loading of an image is cancelled, the JavaScript event that occurs is the abort event.
Was this answer helpful?
0
0