Home > Web Front-end > JS Tutorial > body text

Why Does My Code Not Display an Alert in JSFiddle?

Barbara Streisand
Release: 2024-10-18 10:58:03
Original
1043 people have browsed it

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!");
}
Copy after login
<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>
Copy after login

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!

source:php
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!