Home  >  Article  >  Web Front-end  >  Why Does My Code Not Display an Alert in JSFiddle?

Why Does My Code Not Display an Alert in JSFiddle?

Barbara Streisand
Barbara StreisandOriginal
2024-10-18 10:58:031071browse

Why Does My Code Not Display an Alert in JSFiddle?

Unraveling the JSFiddle Enigma

A simple code snippet that refuses to behave as expected in JSFiddle has left you scratching your head. Stripping down the code to its bare essentials, you've discovered that even this minimalistic example is failing:

function displaymessage() {
  alert("Hello World!");
}
<form>
  <input type="button" value="Click me!" onclick="displaymessage()" />
</form>

<p>By pressing the button above, a function will be called. The function will alert a message.</p>

Despite all efforts, the alert box remains elusive within the JSFiddle.

The Solution: A Tweak in Load Type

The culprit lies in the "Load type" dropdown in the JavaScript settings within JSFiddle. By default, the setting is set to "Wrap - bottom of ". To rectify the issue, simply select "No wrap - bottom of " from the dropdown.

This ensures that the JavaScript code is loaded before any HTML, resolving the problem and allowing the alert box to display its intended message.

The above is the detailed content of Why Does My Code Not Display an Alert in JSFiddle?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn